*
The moose likes Swing / AWT / SWT and the fly likes Threading in Swing two ways? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Threading in Swing two ways?" Watch "Threading in Swing two ways?" New topic
Author

Threading in Swing two ways?

mandlar suurla
Ranch Hand

Joined: Jun 11, 2008
Posts: 67

K i have seen like many people have been using the normal way of implementing the threading(extending from Thread or implement Runnable). But there's also the way to use SwingWorker. Which is to right use ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19675
    
  18

SwingWorker makes the work easier sometimes, with its distinct steps: publish / process for intermediate results, and done when the job is finished.

Still, anything you can do with SwingWorker you can also do yourself with "regular" threads. You'll just have to do more work yourself.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
mandlar suurla
Ranch Hand

Joined: Jun 11, 2008
Posts: 67

Thank you for quick replay, but off curse this isnt my last question . There are also SwingUtilites.invokeLater and SwingUtilites.invokeAndWait, which i know doesn't make new thread, so i dont understand their use in Swing.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by mandlar suurla:
Thank you for quick replay, but off curse this isnt my last question . There are also SwingUtilites.invokeLater and SwingUtilites.invokeAndWait, which i know doesn't make new thread, so i dont understand their use in Swing.

These methods execute a Runnable directly on the event thread; they're intended for short actions that won't delay event processing. In contrast, SwingWorker is for things that will take a long time, but will interact with the GUI occasionally during that time.


[Jess in Action][AskingGoodQuestions]
 
jQuery in Action, 2nd edition
 
subject: Threading in Swing two ways?