Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threading in Swing two ways?

 
mandlar suurla
Ranch Hand
Posts: 67
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
mandlar suurla
Ranch Hand
Posts: 67
Debian Linux PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic