Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to prevent deadlocks in Swing?  RSS feed

Justin Chu
Ranch Hand
Posts: 209
  • 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
Boost this thread!