Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Concurrency in JAVA swings

 
Mohamed Iqzas
Ranch Hand
Posts: 72
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
1
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic