The moose likes Swing / AWT / SWT and the fly likes Event dispatch thread versus model updates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Event dispatch thread versus model updates" Watch "Event dispatch thread versus model updates" New topic

Event dispatch thread versus model updates

Christoph Kleiner

Joined: Nov 24, 2004
Posts: 1
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,
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
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.

I agree. Here's the link:
subject: Event dispatch thread versus model updates
It's not a secret anymore!