The Problem
Home ] Up ] [ The Problem ] Update Swing Only From The EDT ] Avoid Too Much Work in The EDT ] Providing Visual Feedback ] Using a Worker Thread ] Using SwingWorker ]

 

The Single Thread Rule
The GUI main Method

 

Swing was not designed to be fully thread-safe.  Instead, it was designed in such a way that only code running in the event thread -- that is, the thread in which events are delivered, or dispatched -- is allowed to access Swing components. Code running in other threads which attempts to access Swing components is not guaranteed to work correctly, and has the potential of corrupting data in the Swing components..

This was intentional, but it makes things more difficult for the programmer.

This single-threaded, event thread-centric, design results in two distinct problems:

  1. Trying to update Swing components from outside the event thread, and
  2. Trying to do too much work in the event thread
 
The page was last updated February 19, 2008