| 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: 4351
|
|
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: 4351
|
|
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.
|
 |
 |
|
|
subject: Thread safe GUI
|
|
|