BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Easier Swing Threading with SwingWorker

Easier Swing Threading with SwingWorker

Threading is an essential topic in respect to the development of desktop applications. In Swing there are a number of utility libraries to make this programming task easier such as Foxtrot and Spin. The topic is also regularly covered at JavaOne. In a new Java.net tutorial, John O'Conner walks developers through using another utility, SwingWorker, which has been included in the core JRE for the first time with the release of Java 6.

One common mistake of desktop application programmers is misusing the Swing event dispatch thread (EDT). They either unknowingly access user interface (UI) components from non-UI threads or simply disregard the consequences. The result is that applications become unresponsive or sluggish because they perform long-running tasks on the EDT instead of on separate worker threads. Long-running computations or input/output (I/O) bound tasks should never run on the Swing EDT. Finding problematic code may not always be simple, but the Java Platform, Standard Edition 6 (Java SE 6) makes it easier to fix such code by providing the javax.swing.SwingWorker class.

The article covers why desktop applications need to be multi-threaded. It then shows how SwingWorker assists developers in implementing such solutions and includes detail on such features as intermediate results.

Rate this Article

Adoption
Style

BT