• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Event dispatch thread versus model updates

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


D.
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic