Hi, Do anyone of you guys have encountered this problem: CASE: When the Client A trys to lock a record (on the remote server) and that particular record is locked by some other Client B, the first Client A request thread is put on wait/hold. PROBLEM: Now the problem is that- the Client A's screen is unable to refresh. Only when the lock on that particular record is released by Client B and all the waiting threads are notified, then the Client A's screen is able refresh and display's the correct messages etc... QUESTION: How can the Client A's screen be still be refreshed even when it is waiting for the lock to be released ? The locking/unlocking works perfectly on non-GUI clients. Thanks, Arvind
You are doing all of your db work on the Swing event dispatching thread. This leads to the problem that you have noticed. There are ways around this, but all are more complicated. In a real-world app you would likely NOT be able to get away with this behavior, but for the assignment it should be ok. If you are interested in fixing the problem anyway, you will need to create a Runnable object (or subclass Thread, though this is less academically correct) and have this new object do the work on a new thread. Your GUI can either monitor the progress of this work via some kind of flags that you implement on the runnable object (though remember to synchronize access to these flags!) or the runnable can do something on the GUI with SwingUtilities.invokeLater() or SwingUtilities.invokeAndWait(). Be careful NOT to update the GUI from a non-Swing thread, as Swing is NOT threadsafe. A good Swing book will cover this material...
There's excellent tutorial material about Swing and threads on Sun's Java site. You'll probably pass without using worker threads, but you're likely to score higher if you do use them. As mentioned above you won't be able to do without them in the real world. - Peter
posted 18 years ago
Thanks Peter, Matthew and Luis for the information. I shall definitely look into it. -Arvind
I need a new interior decorator. This tiny ad just painted every room in my house purple.
Devious Experiments for a Truly Passive Greenhouse!