aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to prevent deadlocks in Swing? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to prevent deadlocks in Swing?" Watch "How to prevent deadlocks in Swing?" New topic
Author

How to prevent deadlocks in Swing?

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
    
    1
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to prevent deadlocks in Swing?