Swing Event Dispatcher Thread
Even though swing is very important part of the Java platform, truth is that its not thread safe. That means swing component methods called from multiple threads can cause thread interference or memory consistency errors. There are some exceptions to this. There are some swing component methods which are “thread safe” which can be safely invoked from any thread.
Reason why swing is not thread safe is that any attempt to create a thread-safe GUI library faces some fundamental problems. For more on this issue, see the following entry in Graham Hamilton’s blog: MultiThreaded toolkits: A failed dream?
Because of this swing event handling code execution as well as component repaint happens on a special thread known as the event dispatch thread. All the Swing component methods which are not thread safe must be invoked from this 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.

There are two fundamental things to understand about Swing and threads:
- Time-consuming tasks should not be run on the Event Dispatch Thread. Otherwise the application becomes unresponsive. The EDT is busy executing your task and hence can’t process GUI events.
- Swing components should be accessed on the Event Dispatch Thread only. To access components from other threads, you must use SwingUtilities. invokeAndWait, SwingUtilities. invokeLater or SwingWorker.