File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to prevent deadlocks in Swing?

 
Justin Chu
Ranch Hand
Posts: 209
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In our open source application we have a few(many) model classes driving the UI panels. Currently, we take the approach of allowing the models to be fully unsynchronized and making sure that we touch/read/modify these models from within the event thread.

So, when constructing/spawning a worker thread, the required values from the model are passed into the constructor of the worker thread before running it. After it finished, we use invokeLater to process the worker results back into the models. This works only for simple values, such as a String. But it won't work for unsynchronized collections, unless the whole collection is cloned. As the application grow larger, thread safety become more of an concern and I find the need to apply synchronization to part of the models as needed.

Suppose I change the paradigm to create fully thread safe UI models in the first place, will I run into dead lock issues? Is this a better approach?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic