public abstract class Worker<T>
extends java.lang.Object
implements java.lang.Runnable
This class is similar to SwingWorker but less complex.
Constructor and Description |
---|
Worker() |
Modifier and Type | Method and Description |
---|---|
protected abstract T |
construct()
Compute the value to be returned by the
get method. |
protected void |
done(T value)
Called on the event dispatching thread (not on the worker thread)
after the
construct method has returned without throwing
an error. |
protected void |
failed(java.lang.Throwable error)
Called on the event dispatching thread (not on the worker thread)
after the
construct method has thrown an error. |
protected void |
finished()
Called on the event dispatching thread (not on the worker thread)
after the
construct method has finished and after
done() or failed() has been invoked. |
protected java.lang.Throwable |
getError()
Get the error produced by the worker thread, or null if it
hasn't thrown one.
|
protected T |
getValue()
Get the value produced by the worker thread, or null if it
hasn't been constructed yet.
|
void |
run()
Calls #construct on the current thread and invokes
#done on the AWT event dispatcher thread.
|
void |
start()
Starts the Worker on an internal worker thread.
|
public final void run()
run
in interface java.lang.Runnable
protected abstract T construct() throws java.lang.Exception
get
method.java.lang.Exception
protected void done(T value)
construct
method has returned without throwing
an error.
The default implementation does nothing. Subclasses may override this method to perform done actions on the Event Dispatch Thread.
value
- The return value of the construct method.protected void failed(java.lang.Throwable error)
construct
method has thrown an error.
The default implementation prints a stack trace. Subclasses may override this method to perform failure actions on the Event Dispatch Thread.
error
- The error thrown by construct.protected void finished()
construct
method has finished and after
done() or failed() has been invoked.
The default implementation does nothing. Subclasses may override this method to perform completion actions on the Event Dispatch Thread.
protected T getValue()
protected java.lang.Throwable getError()
public void start()