java.lang.Object java.util.concurrent.CancellableTask
Base class for Cancellable
Runnable
actions within the Executor
framework. In addition to
serving as a standalone class, this provides protected
functionality that may be useful when creating customized task
classes.
Nested Class Summary | |
---|---|
protected class |
CancellableTask.InnerCancellableFuture<V>
Implementation of Future methods under the control of a current CancellableTask, which it relies on for methods isDone, isCancelled and cancel. |
Constructor Summary | |
---|---|
protected |
CancellableTask()
Creates a new CancellableTask without a runnable action, which must be set using setRunnable before use. |
|
CancellableTask(Runnable r)
Creates a new CancellableTask which invokes the given Runnable when executed. |
Method Summary | |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Attempt to cancel execution of this task. |
protected void |
done()
Protected method invoked when this task transitions to state isDone (whether normally or via cancellation). |
protected Runnable |
getRunnable()
Return the Runnable forming the basis of this task. |
boolean |
isCancelled()
Returns true if this task was cancelled before it completed normally. |
boolean |
isDone()
Returns true if this task completed. |
protected boolean |
reset()
Reset the run state of this task to its initial state unless it has been cancelled. |
void |
run()
Runs the runnable if not cancelled, maintaining run status. |
protected void |
setCancelled()
Set the state of this task to Cancelled. |
protected void |
setDone()
Set the state of this task to Done, unless already in a Cancelled state, in which Cancelled status is preserved. |
protected void |
setRunnable(Runnable r)
Set the Runnable forming the basis of this task. |
protected boolean |
setRunning()
Attempt to set the state of this task to Running, succeeding only if the state is currently NOT Done, Running, or Cancelled. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CancellableTask(Runnable r)
r
- the runnable action
NullPointerException
- if runnable is nullprotected CancellableTask()
Method Detail |
---|
public boolean cancel(boolean mayInterruptIfRunning)
Cancellable
cancel
in interface Cancellable
mayInterruptIfRunning
- true if the thread executing this
task should be interrupted; otherwise, in-progress tasks are allowed
to complete
public boolean isCancelled()
Cancellable
isCancelled
in interface Cancellable
public boolean isDone()
Cancellable
isDone
in interface Cancellable
protected Runnable getRunnable()
setRunnable(java.lang.Runnable)
protected void setRunnable(Runnable r)
r
- the runnable actiongetRunnable()
protected void setCancelled()
protected void setDone()
protected boolean setRunning()
public void run()
run
in interface Runnable
Thread.run()
protected void done()
protected boolean reset()