|
|
|
|
Swing event handling code runs on a special thread known as the Event Dispatch Thread. Most code that invokes Swing methods also runs on this thread. This is necessary because most Swing object methods are not "thread safe": invoking them from multiple threads risks thread interference or memory consistency errors. The purpose of the Event Dispatch Thread is to serialize all GUI events, so that they cannot interfere with each other. Some Swing component methods are labeled "thread safe" in the API specification; these can be safely invoked from any thread. However, these are in the minority. All other Swing component methods must be invoked from the event dispatch thread. Programs that ignore this rule may function correctly most of the time, but are subject to unpredictable errors that are difficult to reproduce. The most useful of these thread-safe methods include:
Other Swing methods should be presumed not to be thread-safe. |
| The page was last updated February 19, 2008 |