Class SwingWorker


public abstract class SwingWorker
extends java.lang.Object

This is the 3rd version of SwingWorker (also known as SwingWorker 3), an abstract class that you subclass to perform GUI-related work in a dedicated thread. For instructions on using this class, see: http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html Note that the API changed slightly in the 3rd version: You must now invoke start() on the SwingWorker after creating it.

Nested Class Summary

private static class
SwingWorker.ThreadVar
Class to maintain reference to current worker thread under separate synchronization control.

Field Summary

private Thread
thread
private SwingWorker.ThreadVar
threadVar
private Object
value

Constructor Summary

SwingWorker()
Start a thread that will call the construct method and then exit.

Method Summary

abstract Object
construct()
Compute the value to be returned by the get method.
void
finished()
Called on the event dispatching thread (not on the worker thread) after the construct method has returned.
Object
get()
Return the value created by the construct method.
protected Object
getValue()
Get the value produced by the worker thread, or null if it hasn't been constructed yet.
void
interrupt()
A new method that interrupts the worker thread.
private void
setValue(Object x)
Set the value produced by worker thread
void
start()
Start the worker thread.

Field Details

thread

private Thread thread

threadVar

private SwingWorker.ThreadVar threadVar

value

private Object value

Constructor Details

SwingWorker

public SwingWorker()
Start a thread that will call the construct method and then exit.

Method Details

construct

public abstract Object construct()
Compute the value to be returned by the get method.

finished

public void finished()
Called on the event dispatching thread (not on the worker thread) after the construct method has returned.

get

public Object get()
Return the value created by the construct method. Returns null if either the constructing thread or the current thread was interrupted before a value was produced.
Returns:
the value created by the construct method

getValue

protected Object getValue()
Get the value produced by the worker thread, or null if it hasn't been constructed yet.

interrupt

public void interrupt()
A new method that interrupts the worker thread. Call this method to force the worker to stop what it's doing.

setValue

private void setValue(Object x)
Set the value produced by worker thread

start

public void start()
Start the worker thread.