1 |
/* |
2 |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
3 |
* Expert Group and released to the public domain. Use, modify, and |
4 |
* redistribute this code in any way without acknowledgement. |
5 |
*/ |
6 |
|
7 |
package java.util.concurrent; |
8 |
|
9 |
/** |
10 |
* Something, usually a task, that can be cancelled. Cancellation is |
11 |
* performed by the <tt>cancel</tt> method. Additional methods are |
12 |
* provided to determine if the task completed normally or was |
13 |
* cancelled. |
14 |
* |
15 |
* @see FutureTask |
16 |
* @see Executor |
17 |
* @since 1.5 |
18 |
* @author Doug Lea |
19 |
*/ |
20 |
public interface Cancellable { |
21 |
|
22 |
/** |
23 |
* Attempts to cancel execution of this task. This attempt will |
24 |
* fail if the task has already completed, already been cancelled, |
25 |
* or could not be cancelled for some other reason. If successful, |
26 |
* and this task has not started when <tt>cancel</tt> is called, |
27 |
* this task should never run. If the task has already started, |
28 |
* then the <tt>interruptIfRunning</tt> parameter determines |
29 |
* whether the thread executing this task should be interrupted in |
30 |
* an attempt to stop the task. |
31 |
* |
32 |
* @param mayInterruptIfRunning <tt>true</tt> if the thread executing this |
33 |
* task should be interrupted; otherwise, in-progress tasks are allowed |
34 |
* to complete |
35 |
* @return <tt>false</tt> if the task could not be cancelled, |
36 |
* typically because is has already completed normally; |
37 |
* <tt>true</tt> otherwise |
38 |
*/ |
39 |
boolean cancel(boolean mayInterruptIfRunning); |
40 |
|
41 |
/** |
42 |
* Returns <tt>true</tt> if this task was cancelled before it completed |
43 |
* normally. |
44 |
* |
45 |
* @return <tt>true</tt> if task was cancelled before it completed |
46 |
*/ |
47 |
boolean isCancelled(); |
48 |
|
49 |
/** |
50 |
* Returns <tt>true</tt> if this task completed. |
51 |
* |
52 |
* Completion may be due to normal termination, an exception, or |
53 |
* cancellation -- in all of these cases, this method will return |
54 |
* <tt>true</tt>. |
55 |
* |
56 |
* @return <tt>true</tt> if this task completed. |
57 |
*/ |
58 |
boolean isDone(); |
59 |
} |