<s>
SwingWorker	B-Library
is	O
a	O
popular	O
utility	O
class	O
developed	O
by	O
Sun	O
Microsystems	O
for	O
the	O
Swing	B-Language
library	O
of	O
the	O
Java	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
SwingWorker	B-Library
enables	O
proper	O
use	O
of	O
the	O
event	B-Language
dispatching	I-Language
thread	I-Language
.	O
</s>
<s>
As	O
of	O
Java	B-Language
6	O
,	O
SwingWorker	B-Library
is	O
included	O
in	O
the	O
JRE	O
.	O
</s>
<s>
Several	O
incompatible	O
,	O
unofficial	O
,	O
versions	O
of	O
SwingWorker	B-Library
were	O
produced	O
from	O
1998	O
to	O
2006	O
,	O
and	O
care	O
must	O
be	O
taken	O
to	O
avoid	O
the	O
abundant	O
documentation	O
on	O
these	O
versions	O
predating	O
Java	B-Language
6	O
.	O
</s>
<s>
SwingWorker	B-Library
is	O
useful	O
when	O
a	O
time-consuming	O
task	O
has	O
to	O
be	O
performed	O
following	O
a	O
user-interaction	O
event	O
(	O
for	O
example	O
,	O
parsing	O
a	O
huge	O
XML	O
File	O
,	O
on	O
pressing	O
a	O
JButton	O
)	O
.	O
</s>
<s>
This	O
will	O
work	O
,	O
but	O
unfortunately	O
,	O
the	O
loadXML( )	O
method	O
will	O
be	O
called	O
in	O
the	O
same	O
thread	B-Operating_System
as	O
the	O
main	O
Swing	B-Language
thread	B-Operating_System
(	O
the	O
Event	B-Language
dispatching	I-Language
thread	I-Language
)	O
,	O
so	O
if	O
the	O
method	O
needs	O
time	O
to	O
perform	O
,	O
the	O
GUI	B-Application
will	O
freeze	O
during	O
this	O
time	O
.	O
</s>
<s>
This	O
problem	O
is	O
not	O
specific	O
to	O
Java	B-Language
,	O
but	O
common	O
to	O
many	O
GUI	B-Application
models	O
.	O
</s>
<s>
SwingWorker	B-Library
proposes	O
a	O
way	O
to	O
solve	O
it	O
by	O
performing	O
the	O
time-consuming	O
task	O
on	O
another	O
background	O
thread	B-Operating_System
,	O
keeping	O
the	O
GUI	B-Application
responsive	O
during	O
this	O
time	O
.	O
</s>
<s>
The	O
following	O
code	O
defines	O
the	O
SwingWorker	B-Library
,	O
which	O
encapsulates	O
the	O
loadXML( )	O
method	O
call	O
:	O
</s>
<s>
As	O
calling	O
on	O
the	O
Event	B-Language
Dispatch	I-Language
Thread	I-Language
blocks	O
all	O
events	O
,	O
including	O
repaints	O
,	O
from	O
being	O
processed	O
until	O
the	O
task	O
completes	O
,	O
one	O
must	O
avoid	O
calling	O
it	O
before	O
the	O
lengthy	O
operation	O
has	O
finished	O
.	O
</s>
<s>
This	O
method	O
is	O
called	O
on	O
the	O
main	O
event	B-Language
dispatching	I-Language
thread	I-Language
.	O
</s>
<s>
SwingWorker	B-Library
has	O
been	O
part	O
of	O
Java	B-Language
SE	O
only	O
since	O
Java	B-Language
6.0	O
.	O
</s>
<s>
Sun	O
has	O
released	O
versions	O
to	O
be	O
used	O
with	O
earlier	O
JDKs	O
,	O
although	O
they	O
were	O
unofficial	O
versions	O
which	O
were	O
not	O
part	O
of	O
the	O
Java	B-Language
SE	O
and	O
were	O
not	O
mentioned	O
in	O
the	O
standard	O
library	O
documentation	O
.	O
</s>
<s>
The	O
most	O
recent	O
of	O
these	O
versions	O
dates	O
from	O
2003	O
and	O
is	O
often	O
referred	O
to	O
as	O
SwingWorker	B-Library
version	O
3	O
.	O
</s>
<s>
Unfortunately	O
,	O
the	O
JDK	O
6.0	O
SwingWorker	B-Library
and	O
the	O
Version	O
3	O
SwingWorker	B-Library
use	O
different	O
method	O
names	O
and	O
are	O
not	O
compatible	O
.	O
</s>
<s>
The	O
backport	O
version	O
(	O
see	O
below	O
)	O
is	O
now	O
recommended	O
for	O
pre-Java	O
6	O
usage	O
.	O
</s>
<s>
An	O
example	O
for	O
instantiating	O
SwingWorker	B-Library
3	O
is	O
shown	O
below	O
:	O
</s>
<s>
The	O
start( )	O
method	O
executes	O
the	O
code	O
added	O
in	O
the	O
construct( )	O
method	O
in	O
a	O
separate	O
thread	B-Operating_System
.	O
</s>
<s>
To	O
be	O
alerted	O
when	O
the	O
background	O
thread	B-Operating_System
finishes	O
,	O
one	O
need	O
only	O
override	O
the	O
finished( )	O
method	O
.	O
</s>
<s>
The	O
construct( )	O
method	O
can	O
return	O
a	O
result	O
which	O
can	O
later	O
be	O
retrieved	O
using	O
SwingWorker	B-Library
's	O
get( )	O
method	O
.	O
</s>
<s>
A	O
backport	O
of	O
the	O
Java	B-Language
6	O
SwingWorker	B-Library
to	O
Java	B-Language
5	O
is	O
available	O
at	O
.	O
</s>
<s>
Apart	O
from	O
the	O
package	O
name	O
(	O
org.jdesktop.swingworker	O
)	O
,	O
it	O
is	O
compatible	O
with	O
the	O
Java	B-Language
6	O
SwingWorker	B-Library
.	O
</s>
