<s>
The	O
event	B-Language
dispatching	I-Language
thread	I-Language
(	O
EDT	O
)	O
is	O
a	O
background	O
thread	B-Operating_System
used	O
in	O
Java	B-Language
to	O
process	O
events	O
from	O
the	O
Abstract	B-Language
Window	I-Language
Toolkit	I-Language
(	O
AWT	B-Language
)	O
graphical	B-Application
user	I-Application
interface	I-Application
event	B-Operating_System
queue	I-Operating_System
.	O
</s>
<s>
It	O
is	O
an	O
example	O
of	O
the	O
generic	O
concept	O
of	O
event-driven	B-Application
programming	I-Application
,	O
that	O
is	O
popular	O
in	O
many	O
other	O
contexts	O
than	O
Java	B-Language
,	O
for	O
example	O
,	O
web	B-Application
browsers	I-Application
,	O
or	O
web	B-Application
servers	I-Application
.	O
</s>
<s>
The	O
events	O
are	O
primarily	O
update	O
events	O
that	O
cause	O
user	O
interface	O
components	B-Architecture
to	O
redraw	O
themselves	O
,	O
or	O
input	O
events	O
from	O
input	B-Device
devices	I-Device
such	O
as	O
the	O
mouse	O
or	O
keyboard	O
.	O
</s>
<s>
The	O
AWT	B-Language
uses	O
a	O
single-threaded	B-Operating_System
painting	O
model	O
in	O
which	O
all	O
screen	O
updates	O
must	O
be	O
performed	O
from	O
a	O
single	B-Operating_System
thread	I-Operating_System
.	O
</s>
<s>
The	O
event	B-Language
dispatching	I-Language
thread	I-Language
is	O
the	O
only	O
valid	O
thread	B-Operating_System
to	O
update	O
the	O
visual	O
state	O
of	O
visible	O
user	O
interface	O
components	B-Architecture
.	O
</s>
<s>
Updating	O
visible	O
components	B-Architecture
from	O
other	O
threads	B-Operating_System
is	O
the	O
source	O
of	O
many	O
common	O
bugs	B-Error_Name
in	O
Java	B-Language
programs	B-Application
that	O
use	O
Swing	B-Language
.	O
</s>
<s>
The	O
event	B-Language
dispatching	I-Language
thread	I-Language
is	O
called	O
the	O
primordial	O
worker	O
in	O
Adobe	B-Operating_System
Flash	I-Operating_System
and	O
the	O
UI	O
thread	B-Operating_System
in	O
SWT	B-Application
,	O
.NET	B-Application
Framework	I-Application
and	O
Android	B-Application
.	O
</s>
<s>
A	O
software	O
application	O
normally	O
consists	O
of	O
multiple	O
threads	B-Operating_System
and	O
a	O
single	O
GUI	B-Application
data	O
structure	O
.	O
</s>
<s>
This	O
means	O
GUI	B-Application
is	O
a	O
shared	O
data	O
structure	O
and	O
some	O
synchronization	O
is	O
needed	O
to	O
ensure	O
that	O
only	O
one	O
thread	B-Operating_System
accesses	O
it	O
at	O
a	O
time	O
.	O
</s>
<s>
Though	O
AWT	B-Language
and	O
Swing	B-Language
expose	O
the	O
(	O
thread	B-Operating_System
unsafe	I-Operating_System
)	O
methods	O
to	O
create	O
and	O
access	O
the	O
GUI	B-Application
components	B-Architecture
and	O
these	O
methods	O
are	O
visible	O
to	O
all	O
application	O
threads	B-Operating_System
,	O
likewise	O
in	O
other	O
GUI	B-Library
frameworks	I-Library
,	O
only	O
a	O
single	O
,	O
Event	B-Language
Dispatching	I-Language
thread	I-Language
has	O
the	O
right	O
to	O
execute	O
these	O
methods	O
.	O
</s>
<s>
Since	O
programmers	O
often	O
miss	O
this	O
requirement	O
,	O
third-party	O
Look	O
and	O
Feels	O
,	O
like	O
go	O
as	O
far	O
as	O
to	O
refuse	O
to	O
instantiate	O
any	O
Swing	B-Language
component	O
when	O
not	O
running	O
within	O
the	O
Event	B-Language
Dispatch	I-Language
Thread	I-Language
,	O
to	O
prevent	O
such	O
a	O
coding	O
mistake	O
.	O
</s>
<s>
Access	O
to	O
the	O
GUI	B-Application
is	O
serialized	O
and	O
other	O
threads	B-Operating_System
may	O
submit	O
some	O
code	O
to	O
be	O
executed	O
in	O
the	O
EDT	O
through	O
a	O
EDT	O
message	B-Operating_System
queue	I-Operating_System
.	O
</s>
<s>
That	O
is	O
,	O
likewise	O
in	O
other	O
GUI	B-Library
frameworks	I-Library
,	O
the	O
Event	B-Language
Dispatching	I-Language
Thread	I-Language
spends	O
its	O
life	O
pumping	O
messages	O
:	O
it	O
maintains	O
a	O
message	B-Operating_System
queue	I-Operating_System
of	O
actions	O
to	O
be	O
performed	O
over	O
GUI	B-Application
.	O
</s>
<s>
These	O
requests	O
are	O
submitted	O
to	O
the	O
queue	O
by	O
system	O
and	O
any	O
application	O
thread	B-Operating_System
.	O
</s>
<s>
EDT	O
consumes	O
them	O
one	O
after	O
another	O
and	O
responds	O
by	O
updating	O
the	O
GUI	B-Application
components	B-Architecture
.	O
</s>
<s>
The	O
important	O
requirement	O
imposed	O
on	O
all	O
messages	O
is	O
that	O
they	O
must	O
be	O
executed	O
quickly	O
for	O
the	O
GUI	B-Application
to	O
stay	O
responsive	O
.	O
</s>
<s>
Otherwise	O
,	O
the	O
message	O
loop	O
is	O
blocked	O
and	O
GUI	B-Application
freezing	O
is	O
experienced	O
.	O
</s>
<s>
GUI	B-Application
components	B-Architecture
support	O
the	O
lists	O
of	O
callbacks	O
,	O
called	O
Listeners	O
,	O
which	O
are	O
typically	O
populated	O
when	O
the	O
components	B-Architecture
are	O
created	O
.	O
</s>
<s>
EDT	O
executes	O
the	O
listeners	O
when	O
user	O
excitates	O
the	O
components	B-Architecture
somehow	O
(	O
button	O
is	O
clicked	O
,	O
mouse	O
is	O
moved	O
,	O
item	O
is	O
selected	O
,	O
focus	O
is	O
lost	O
,	O
component	O
resized	O
and	O
so	O
on	O
.	O
)	O
</s>
<s>
For	O
short	O
tasks	O
that	O
must	O
access/modify	O
GUI	B-Application
periodically	O
or	O
at	O
specific	O
time	O
,	O
javax.swing.Timer	O
is	O
used	O
.	O
</s>
<s>
It	O
can	O
be	O
considered	O
as	O
an	O
invisible	O
GUI	B-Application
component	O
,	O
whose	O
listeners	O
are	O
registered	O
to	O
fire	O
at	O
specific	O
time(s )	O
.	O
</s>
<s>
Other	O
application	O
threads	B-Operating_System
can	O
pass	O
some	O
code	O
to	O
be	O
executed	O
in	O
the	O
event	B-Language
dispatching	I-Language
thread	I-Language
by	O
means	O
of	O
helper	O
classes	O
(	O
or	O
if	O
you	O
are	O
doing	O
AWT	B-Language
)	O
.	O
</s>
<s>
from	O
the	O
event	B-Language
dispatching	I-Language
thread	I-Language
.	O
</s>
<s>
The	O
method	O
invokeAndWait( )	O
should	O
never	O
be	O
called	O
from	O
the	O
event	O
dispatching	O
threadit	O
will	O
throw	O
an	O
exception	B-General_Concept
.	O
</s>
<s>
The	O
method	O
or	O
can	O
be	O
called	O
to	O
determine	O
if	O
the	O
current	O
thread	B-Operating_System
is	O
the	O
event	B-Language
dispatching	I-Language
thread	I-Language
.	O
</s>
<s>
They	O
are	O
normally	O
intended	O
to	O
deliver	O
the	O
result	O
of	O
a	O
lengthy	O
computation	O
to	O
the	O
GUI	B-Application
(	O
user	O
)	O
.	O
</s>
<s>
Both	O
execution	O
of	O
a	O
task	O
in	O
another	O
thread	B-Operating_System
and	O
presenting	O
the	O
results	O
in	O
the	O
EDT	O
can	O
be	O
combined	O
by	O
means	O
of	O
worker	B-Library
design	I-Library
pattern	I-Library
.	O
</s>
<s>
The	O
javax.swing.SwingWorker	B-Library
class	O
,	O
developed	O
by	O
Sun	O
Microsystems	O
,	O
is	O
an	O
implementation	O
of	O
the	O
worker	B-Library
design	I-Library
pattern	I-Library
,	O
and	O
as	O
of	O
Java	B-Language
6	O
is	O
part	O
of	O
standard	O
Swing	B-Language
distribution	O
.	O
</s>
<s>
SwingWorker	B-Library
is	O
normally	O
invoked	O
from	O
EDT-executed	O
event	O
Listener	O
to	O
perform	O
a	O
lengthy	O
task	O
in	O
order	O
not	O
to	O
block	O
the	O
EDT	O
.	O
</s>
<s>
If	O
you	O
use	O
Groovy	B-Application
and	O
groovy.swing.SwingBuilder	O
,	O
you	O
can	O
use	O
doLater( )	O
,	O
doOutside( )	O
,	O
and	O
edt( )	O
.	O
</s>
<s>
SwingWorker	B-Library
is	O
normally	O
created	O
for	O
a	O
lengthy	O
tasks	O
by	O
EDT	O
while	O
handling	O
callback	O
(	O
Listener	O
)	O
events	O
.	O
</s>
<s>
Spawning	O
a	O
worker	O
thread	B-Operating_System
,	O
EDT	O
proceeds	O
handling	O
current	O
message	O
without	O
waiting	O
the	O
worker	O
to	O
complete	O
.	O
</s>
<s>
Often	O
,	O
your	O
EDT	O
handles	O
a	O
GUI	B-Application
component	O
action	O
,	O
which	O
demands	O
the	O
user	O
to	O
make	O
a	O
choice	O
by	O
means	O
of	O
another	O
dialog	O
,	O
like	O
JFileChooser	O
,	O
which	O
pops	O
up	O
,	O
stays	O
responsive	O
while	O
user	O
picks	O
its	O
option	O
and	O
action	O
proceeds	O
with	O
selected	O
file	O
only	O
after	O
"	O
OK	O
"	O
button	O
is	O
pressed	O
.	O
</s>
<s>
You	O
see	O
,	O
this	O
takes	O
time	O
(	O
user	O
responds	O
in	O
matter	O
of	O
seconds	O
)	O
and	O
you	O
need	O
a	O
responsive	O
GUI	B-Application
(	O
the	O
messages	O
are	O
still	O
pumped	O
in	O
EDT	O
)	O
during	O
all	O
this	O
time	O
while	O
EDT	O
is	O
blocking	O
(	O
it	O
does	O
not	O
handle	O
newer	O
,	O
e.g.	O
</s>
<s>
The	O
open	O
source	O
Foxtrot	O
project	O
emulates	O
the	O
Swing	B-Language
message	O
loop	O
pumping	O
to	O
provide	O
the	O
"	O
synchronous	O
"	O
execution	O
mechanism	O
for	O
arbitrary	O
user	O
tasks	O
,	O
which	O
proceeds	O
only	O
after	O
the	O
worker	O
completes	O
the	O
task	O
.	O
</s>
<s>
Since	O
Java	B-Language
1.7	O
,	O
Java	B-Language
provides	O
standard	O
solution	O
for	O
custom	O
secondary	O
message	O
loops	O
by	O
exposing	O
createSecondaryLoop( )	O
in	O
system	O
EventQueue( )	O
.	O
</s>
