public abstract class Task
extends java.lang.Object
run() method with the time-consuming code, and not worry about
exceptions, for example:
Task task = new Task()
{
public Object run() throws InterruptedException
{
Thread.sleep(10000);
return null;
}
};
Exceptions and Errors thrown by the run() method will be rethrown automatically by
Worker.post(Task) or by ConcurrentWorker.post(Task)Worker,
ConcurrentWorker| Modifier and Type | Field and Description |
|---|---|
private boolean |
completed |
private java.lang.Object |
result |
private java.security.AccessControlContext |
securityContext |
private java.lang.Throwable |
throwable |
| Modifier | Constructor and Description |
|---|---|
protected |
Task()
Creates a new Task.
|
| Modifier and Type | Method and Description |
|---|---|
private java.lang.Object |
getResult()
Returns the result of this Task operation, as set by
setResult(java.lang.Object). |
protected java.lang.Object |
getResultOrThrow()
Returns the result of this Task operation, as set by
setResult(java.lang.Object). |
(package private) java.security.AccessControlContext |
getSecurityContext()
Returns the protection domain stack at the moment of instantiation of this Task.
|
(package private) java.lang.Throwable |
getThrowable()
Returns the throwable as set by
setThrowable(java.lang.Throwable). |
boolean |
isCompleted()
Returns whether the execution of this Task has been completed or not.
|
(package private) void |
postRun()
Callback invoked from the worker thread to perform some operation just after the Task
has been
completed. |
(package private) void |
reset()
Resets the internal status of this Task, that can be therefore be reused.
|
abstract java.lang.Object |
run()
The method to implement with time-consuming code.
|
(package private) void |
setCompleted(boolean value)
Sets the completion status of this Task.
|
(package private) void |
setResult(java.lang.Object result)
Sets the result of this Task operation, as returned by the
run() method. |
(package private) void |
setThrowable(java.lang.Throwable x)
Sets the throwable eventually thrown by the
run() method. |
private java.lang.Object result
private java.lang.Throwable throwable
private boolean completed
private java.security.AccessControlContext securityContext
public abstract java.lang.Object run()
throws java.lang.Exception
java.lang.Exceptionprotected final java.lang.Object getResultOrThrow()
throws java.lang.Exception
setResult(java.lang.Object).
If an exception or an error is thrown by run(), it is rethrown here.
Synchronized since the variables are accessed from 2 threads
Accessed from the AWT Event Dispatch Thread.java.lang.ExceptionsetResult(java.lang.Object),
setThrowable(java.lang.Throwable)private final java.lang.Object getResult()
setResult(java.lang.Object).
Synchronized since the variable is accessed from 2 threads
Accessed from the AWT Event Dispatch Thread.getResultOrThrow()final void setResult(java.lang.Object result)
run() method.
Synchronized since the variable is accessed from 2 threads
Accessed from the worker thread.
Package protected, used by AbstractWorkerThreadgetResultOrThrow(),
getResult()final java.lang.Throwable getThrowable()
setThrowable(java.lang.Throwable).
Synchronized since the variable is accessed from 2 threads
Accessed from the AWT Event Dispatch Thread.final void setThrowable(java.lang.Throwable x)
run() method.
Synchronized since the variable is accessed from 2 threads
Accessed from the worker thread.
Package protected, used by AbstractWorkerThreadgetThrowable()public final boolean isCompleted()
final void setCompleted(boolean value)
AbstractWorkerThreadisCompleted()final java.security.AccessControlContext getSecurityContext()
AbstractWorkerThreadTask()final void reset()
isCompleted()void postRun()
completed.