Our client-server application updates the client-sided data structure whenever data is received from the server. In order to "synchronize" this with the repainting of the swing GUI's (because during the repainting, the data structure might change and we also need to modify the swing GUI according to the new data (enabling/disabling of buttons for instance)), we do those updates in the event dispatching thread by calling SwingUtilities.invokeAndWait (we need to use "wait" because otherwise, we will have race conditions stemming from multiple updates from the server).
This works fine, but in some cases, the call blocks and never returns. Questions:
A) Is there a better way to achieve what we need?
B) If not: what is the reason for the blocking or how can we find out, what the reason is?
One possible solution I can think of is to somehow prevent swing from repainting asynchronously, until we are sure the the data structure won't be modified. But I don't believe this is feasible/possible. And synchronizing (by using locks) on the data structures is probably also wrong.
Thanks a lot, Christoph
Joined: Dec 12, 2002
A) Sounds good to me, it's what we do, although we use invokeLater. I don't think there is a possibility of race conditions as I believe the events posted will be processed in the order they were added.
B) Sounds like your code is either entering a infinite loop, or you have deadlock. To find the reason, just debug your code. Find out where the program is stopping.