Results 1 to 9 of 9
Like Tree2Likes
  • 1 Post By Fubarable
  • 1 Post By DarrylBurke

Thread: EDT Invokeandwait

  1. #1
    paulrussell70 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default EDT Invokeandwait

    Hi Forums

    I use invokelater whenever it's needed. But sometimes I actually want to lock the GUI until an event finishes.

    I have a Client/Server POS system, it's finished and in testing. But some annoying and hard to trace glitches remain. I think they are linked to thread problems.

    In the main Sales window I need to make a number of accesses to the server. These involve using Serializable and ObjectOutputStream. This is to do with Concurrency checking which involves a token which only one client can hold at anytime- Then program is writing the various transactions over to the server. On the back end off the server, sits the Apache Derby database. Everything has been working fairly well until recently. The database is now pretty large approaching a gigabyte of data. Which makes me suspect that perhaps the problem maybe to do with delays in Derby replying to requests due to data size.

    Within the main POS window I want to pause all events until the server replies. I cannot use InvokeandWait here because I'm in the EDT thread, it throws up an error.

    Questions are:

    1---What am I supposed to do with this kind of problem?? i.e where I'm waiting on network stuff but I want to pause everything until I get a reply from the server.
    2---If the server somehow drops an object through some network problem will I get to know about it through an error? Does Object/In/Outputstream time out and throw an error?

    I can make a test rig, but am just looking for a general advice on best way to tackle this kind of thing.

    Many thanks in advance for any helpful comments given

    Best regards
    Paul

  2. #2
    paulrussell70 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: EDT Invokeandwait

    The problems that I have been encountering manifest as the GUI just locking up. Just the behaviour I wanted. Investigating my server logs leads me to the conclusion that the server responded, but the response never found its way back to the read on the client. Just the desired behaviour, but its not clear if its some kind of threading problem causing the GUI to lock up, over if the Objectinputstream is just still waiting for a response!

    Thanks again!

  3. #3
    bigjo is offline Member
    Join Date
    Jul 2011
    Posts
    27
    Rep Power
    0

    Default Re: EDT Invokeandwait

    Why do you do the database link in you EDT thread? You have to do that in a new Thread. The EDT thread will be blocked when your new Thread is running, unless you call the method invokeLater().

  4. #4
    paulrussell70 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: EDT Invokeandwait

    Thanks for reply.

    I'm making calls to the server, which is a Java wrapper around the database. I'm doing these calls straight from inside my POS window because I precisely want the GUI to sit and wait whilst the server responds. I have a set of products shown in the POS window at this point and I don't want them to be cleared until the server responds. But I also don't want any unexpected behaviour from the program.

    cheers Paul

  5. #5
    paulrussell70 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: EDT Invokeandwait

    What I want is InvokeandWait() but from inside the EDT. This is not the typical GUI type scenario where I want the user to be able to click away etc. I should just wait on the result ideally.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: EDT Invokeandwait

    No, you don't want to do what you're doing. What you want to do is give your GUI an inactivate method of some sort, or perhaps better a setEnabled(boolean enabled) for the whole GUI where you make user interactable components disabled or enabled whichever you choose (one way to do this is by using the glasspane), then disable your GUI, call your database stuff in a background thread, update the GUI on the EDT as data comes in, and then reactivate the GUI when it is ready again for user input. Else you will likely keep messing up your application.
    DarrylBurke likes this.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: EDT Invokeandwait

    Two tips which might help in imjplementing the approach suggested by Fubarable, both by camickr:
    Disabled Panel Java Tips Weblog
    Disabled Glass Pane Java Tips Weblog

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    paulrussell70 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: EDT Invokeandwait

    Hi Furable

    Thanks for youR reply. You are right of course. It's just such a massively complicated window to disable, but needs must I guess.

    I'll move the network calls into a background thread, the main window will have to be disabled. I can use a Swingworker I guess, put up some kind of box telling user transactions are being committed, then fire an event from the Swingworker once the transactions are completed/or not. And so on for the other windows like add products/edit existing product. It seems such a long way around such a common task that occurs in nearly everY other window, to make access to remote data from inside a window without having to get into Threads. I did something similar before so I've got the code for it somewhere.

    Thanks for the reply. I sure appreciate it. Have a good day/evening out where you are. Im on GMT here!

    Best regards Paul
    Last edited by paulrussell70; 11-25-2011 at 10:30 PM.

  9. #9
    paulrussell70 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: EDT Invokeandwait

    So I just add my panel into the DisabledPanel? That's a very neat idea. If you lived close I'd buy you a drink! Thanks again.

    <code>
    JPanel somePanel = new JPanel();
    DisabledPanel disabledPanel = new DisabledPanel(somePanel);
    frame.add(disabledPanel);
    ...
    disabledPanel.setEnabled(false);
    </code>

Similar Threads

  1. Replies: 0
    Last Post: 07-03-2008, 08:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •