my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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: 19654
    
  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]
 
 
subject: Threading in Swing two ways?
 
Similar Threads
When to use Threads
Accessing Web context in a thread in WAS 5.1
Is RMI adequate?
SwingWorker
Object Pool