java.util.concurrent
Interface Cancellable

All Known Subinterfaces:
Future, ScheduledCancellable, ScheduledFuture
All Known Implementing Classes:
CancellableTask, CancellableTask.InnerCancellableFuture, FutureTask, PrivilegedFutureTask

public interface Cancellable

Something, usually a task, that can be cancelled. Cancellation is performed by the cancel method. Additional methods are provided to determine if the task completed normally or was cancelled.

Since:
1.5
See Also:
FutureTask, Executor

Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
          Attempt to cancel execution of this task.
 boolean isCancelled()
          Returns true if this task was cancelled before it completed normally.
 boolean isDone()
          Returns true if this task completed.
 

Method Detail

cancel

boolean cancel(boolean mayInterruptIfRunning)
Attempt to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the interruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

Parameters:
mayInterruptIfRunning - true if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete
Returns:
false if the task could not be cancelled, typically because is has already completed normally; true otherwise

isCancelled

boolean isCancelled()
Returns true if this task was cancelled before it completed normally.

Returns:
true if task was cancelled before it completed

isDone

boolean isDone()
Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.

Returns:
true if this task completed.