*** Welcome to piglix ***

Event dispatching thread


The event dispatching thread (EDT) is a background thread used in Java to process events from the Abstract Window Toolkit (AWT) graphical user interface event queue. It is an example of the generic concept of event-driven programming, that is popular in many other contexts than Java, for example, web browsers, or web servers.

The events are primarily update events that cause user interface components to redraw themselves, or input events from input devices such as the mouse or keyboard. The AWT uses a single-threaded painting model in which all screen updates must be performed from a single thread. The event dispatching thread is the only valid thread to update the visual state of visible user interface components. Updating visible components from other threads is the source of many common bugs in Java programs that use Swing. The event dispatching thread is called the primordial worker in Adobe Flash and the UI thread in SWT, .NET Framework and Android.

A software application normally consists of multiple threads and a single GUI data structure. This means GUI is a shared data structure and some synchronization is needed to ensure that only one thread accesses it at a time. Though AWT and Swing expose the (thread unsafe) methods to create and access the GUI components and these methods are visible to all application threads, likewise in other GUI frameworks, only a single, Event Dispatching thread has the right to execute these methods. Since programmers often miss this requirement, third-party Look and Feels, like Substance go as far as to refuse to instantiate any Swing component when not running within the Event Dispatch Thread, to prevent such a coding mistake. Access to the GUI is serialized and other threads may submit some code to be executed in the EDT through a EDT message queue.


...
Wikipedia

...