V
- Type of result generated by the task.public abstract class SwingBackgroundTask<V> extends Object
Modifier | Constructor and Description |
---|---|
protected |
SwingBackgroundTask() |
Modifier and Type | Method and Description |
---|---|
void |
execute()
Asynchronous call that begins execution of the task and returns immediately.
|
protected void |
onError(Throwable throwable)
This method is invoked, on the Event Dispatch Thread, if there is an
exception or error executing the
performTask() method. |
protected abstract V |
performTask()
Performs the processing of the task and returns a result.
|
protected void |
postProcessing(V result)
This method is invoked, on the Event Dispatch Thread, after the task
has been executed.
|
void |
waitForCompletion()
Waits for the execution of this task to complete.
|
public void execute()
performTask()
method will be invoked on a background thread and,
when it has completed, postProcessing(Object)
will be invoked on the
Event Dispatch Thread (or, if there is an exception, onError(Throwable)
will be invoked instead - also on the EDT).public void waitForCompletion() throws InterruptedException
execute()
method has not yet been invoked, this method will block indefinitely.InterruptedException
- If the thread executing the task
is interrupted.protected abstract V performTask() throws Exception
Exception
- The task may throw an exception, in which case
the onError(Throwable)
method will be invoked instead of
postProcessing(Object)
.protected void postProcessing(V result)
result
- The result from the performTask()
method.protected void onError(Throwable throwable)
performTask()
method.
This default implementation displays a message dialog with details of the
exception. It may be over-ridden in sub-classes.throwable
- The exception or error that was thrown while executing
the task.