wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Concurrency in JAVA swings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Concurrency in JAVA swings" Watch "Concurrency in JAVA swings" New topic
Author

Concurrency in JAVA swings

Mohamed Iqzas
Ranch Hand

Joined: Jan 02, 2012
Posts: 58

I am using JAVA Swings for a while. But never understood clearly the threading issues with it.

Just knew that SwingUtilities.invokeLater will avoid hanging of the application by some means of exceuting in a non-EDT thread (please correct me if i'm wrong).

How shall I handle concurrency inside Event Dispatch Thread. Since most of the functionality is handled inside action listeners, my application hangs everytime even if I launch the application using invokeLater method. I am handling db calls from a method inside action listeners.

Is there any improved way of handling concurrency for Swings in JAVA 7? What am I missing to do in my code? I have read few forums on this topic but never actually understood what needs to be done for concurrency in Swings.

Thanks in advance.
Bernhard Goetz
Ranch Hand

Joined: Jan 07, 2013
Posts: 35

Hi Mohamed,
I'd like to point you to the SwingWorker class. Here's an excerpt from the javadoc:

SwingWorker is designed for situations where you need to have a long running task run in a background thread and provide updates to the UI either when done, or while processing.


Code that handles creation of the GUI or interactivity with the GUI are handled within the Event Dispatch Thread (EDT). Anything else should be handled in a separated thread. The SwingWorker class
assists you in doing exactly this thing. It also provides a way to inform your Swing UI if the process has been finished (See SwingWorker.done()) . Try to read the javadoc of the class, there are also samples noted for this case.

I hope this is of any help for you.

Regards,
Bernhard

Edit: There is also a section about SwingWorkers in the Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Concurrency in JAVA swings
 
Similar Threads
SSL support with swings
generate a tree structure
Message Box problem
threads in applet
SSL support with swings