Search code examples
javaswingworker

Why SwingWorker? Why not just Thread or Runnable?


What are the advantages of using SwingWorker instead of Thread or Runnable?


Solution

  • Thread and Runnable were part of Java 1.0; they're as good as they were back then.

    The new concurrency classes distill all that's been learned about multi-threading since then (thank you, Doug Lea and others). Writing multi-threaded code is terribly difficult. The new concurrency classes, including SwingWorker, try to make that easier.

    Start by noting the generics for strong typing. There's a mechanism built in to publish and process both final and intermediate results.

    It'd be possible to mimic these with Thread and Runnable, but SwingWorker has done it for you.