public abstract class Task extends Object
| Constructor and Description |
|---|
Task() |
| Modifier and Type | Method and Description |
|---|---|
abstract Object |
call()
Compute the value to be returned by the
get method. |
protected void |
complete(Object returnValue,
Throwable error)
Notification by the ExecutionService that the call is complete.
|
void |
finish()
Allow event dispatching thread to complete the task
after the
call method has returned. |
Object |
get()
Return the value created by the
call method. |
protected Executor |
getDefaultExecutor()
Get default executor for this task.
|
protected Executor |
getExecutor()
Get current active executor for this task.
|
Throwable |
getThrowable()
Return the value created by the
call method. |
protected long |
getTimeoutPeriod()
Get the timeout period for this task.
|
boolean |
isDone()
Return true if
call has completed. |
boolean |
isFailed()
Return true if
call failed. |
protected void |
markCompleted(Object returnValue,
Throwable error)
mark this task as completed.
|
void |
start()
Submit the task for execution.
|
void |
start(Executor executor)
Submit the task for execution on the specified Executor.
|
void |
timeout()
Allow timeout to be performed.
|
public void start()
public void start(Executor executor)
executor - the Executor on which to submit the taskprotected Executor getDefaultExecutor()
Subclasses are expected to implement this if the zero-arg variant of start is used.
protected long getTimeoutPeriod()
Generally this returns 0, but subclasses may override to indicate the
amount of time to wait for the next task to be submitted to the
Executor. If more than the specified time elapses before a subsequent
task is submitted, the Executor will invoke timeout on this
task.
protected Executor getExecutor()
Returns null if the Task has not been started.
protected void complete(Object returnValue, Throwable error)
This posts an invokeLater for the finish
operation.
returnValue - the result of the call methoderror - any error that occurred during callprotected void markCompleted(Object returnValue, Throwable error)
Called as part of complete, and performs all actions
except ensureing finish is called.
returnValue - the result of the call methoderror - any error that occurred during callpublic abstract Object call() throws Exception
get method.
This is analgous to construct in the SwingWorker class.
Exception - if the operation failspublic void finish()
call method has returned.
This is analgous to finished in the SwingWorker class.
public void timeout()
Executes in executor's thread, and is called for tasks that return
a positive value for getTimeoutPeriod and when the subsequent
task submitted to the Executor does not occur within the specified
period.
public Object get()
call method.
Returns null if an exception occurred in the call
method.
call methodpublic Throwable getThrowable()
call method.
Returns null if no exception occurred in the call
method.
call methodpublic boolean isFailed()
call failed.call method
has failed; false otherwisepublic boolean isDone()
call has completed.call method
has completed; false otherwiseCopyright © 2025. All rights reserved.