File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Concurrency in JAVA swings" Watch "Concurrency in JAVA swings" New topic

Concurrency in JAVA swings

Mohamed Iqzas
Ranch Hand

Joined: Jan 02, 2012
Posts: 72

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: 57

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.


Edit: There is also a section about SwingWorkers in the Java Tutorial
I agree. Here's the link:
subject: Concurrency in JAVA swings
It's not a secret anymore!