aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Thread safe GUI 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 » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Thread safe GUI" Watch "Thread safe GUI" New topic
Author

Thread safe GUI

Matt Pavlovich
Ranch Hand

Joined: Aug 14, 2010
Posts: 98
Hey guys,

I have made my GUI thread safe as per the Java tutorials buy launching my windows with:


However, I notice this code is absent from the SCJD book and was wondering if there is a reason not to use it in a multi-threaded environment such as this project.

Thanks,
Matt
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5593
    
  14

Using the search engine: thread1 and thread2.

Matt Pavlovich wrote:a multi-threaded environment such as this project

My client is not multi-threaded, my server is. If I would perform a major time-consuming task and I want not to freeze my GUI I would use the SwingUtilities.invokeLater(), but in this project I don't see any advantages.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Marcel van den Boer
Greenhorn

Joined: Apr 19, 2011
Posts: 21

Roel De Nijs wrote:If I would perform a major time-consuming task and I want not to freeze my GUI I would use the SwingUtilities.invokeLater()


They invented SwingWorker for that . If you use invokeLater() for time consuming tasks, the GUI would freeze anyway.

It's true you'll probably won't absolutely need to use invokeLater() to construct your GUI, but as I understand it, it is a good practice to do so anyway. The Swing documentation does not say you should only use invokeLater() in a multi-threaded application, it just says you should use it when constructing your GUI (http://download.oracle.com/javase/6/docs/api/javax/swing/package-summary.html).

But you must do what you feel is right, of course...


OCPJP
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5593
    
  14

Marcel van den Boer wrote:They invented SwingWorker for that . If you use invokeLater() for time consuming tasks, the GUI would freeze anyway.

Oh, my mistake I have limited Swing experience, for my current project (desktop application) we are using RCP as technology, no Swing anymore.
Matt Pavlovich
Ranch Hand

Joined: Aug 14, 2010
Posts: 98
Thanks, guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread safe GUI