1 |
tim |
1.1 |
/* |
2 |
dl |
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 |
tim |
1.1 |
*/ |
6 |
|
|
|
7 |
|
|
package java.util.concurrent; |
8 |
|
|
|
9 |
|
|
/** |
10 |
brian |
1.6 |
* Something, usually a task, that can be cancelled. Cancellation is |
11 |
dl |
1.3 |
* performed by the <tt>cancel</tt> method. Additional methods are |
12 |
|
|
* provided to determine if the task completed normally or was |
13 |
|
|
* cancelled. |
14 |
tim |
1.1 |
* |
15 |
|
|
* @since 1.5 |
16 |
|
|
* |
17 |
|
|
* @spec JSR-166 |
18 |
dl |
1.8 |
* @revised $Date: 2003/06/24 14:34:47 $ |
19 |
|
|
* @editor $Author: dl $ |
20 |
brian |
1.6 |
* @see FutureTask |
21 |
|
|
* @see Executor |
22 |
dl |
1.7 |
* @author Doug Lea |
23 |
tim |
1.1 |
*/ |
24 |
|
|
public interface Cancellable { |
25 |
|
|
|
26 |
|
|
/** |
27 |
brian |
1.6 |
* Attempt to cancel execution of this task. This attempt will |
28 |
dl |
1.7 |
* fail if the task has already completed, already been cancelled, |
29 |
|
|
* or could not be cancelled for some other reason. If successful, |
30 |
|
|
* and this task has not started when <tt>cancel</tt> is called, |
31 |
|
|
* this task will never run. If the task has already started, |
32 |
|
|
* then the <tt>interruptIfRunning</tt> parameter determines |
33 |
|
|
* whether the thread executing this task should be interrupted in |
34 |
|
|
* an attempt to stop the task. |
35 |
tim |
1.1 |
* |
36 |
jozart |
1.4 |
* @param mayInterruptIfRunning <tt>true</tt> if the thread executing this |
37 |
tim |
1.1 |
* task should be interrupted; otherwise, in-progress tasks are allowed |
38 |
|
|
* to complete |
39 |
dl |
1.5 |
* @return <tt>false</tt> if the task could not be cancelled, |
40 |
|
|
* typically because is has already completed normally; |
41 |
|
|
* <tt>true</tt> otherwise |
42 |
tim |
1.1 |
*/ |
43 |
|
|
boolean cancel(boolean mayInterruptIfRunning); |
44 |
|
|
|
45 |
|
|
/** |
46 |
|
|
* Returns <tt>true</tt> if this task was cancelled before it completed |
47 |
|
|
* normally. |
48 |
|
|
* |
49 |
|
|
* @return <tt>true</tt> if task was cancelled before it completed |
50 |
|
|
*/ |
51 |
|
|
boolean isCancelled(); |
52 |
|
|
|
53 |
|
|
/** |
54 |
dl |
1.8 |
* Returns <tt>true</tt> if this task completed. |
55 |
tim |
1.1 |
* |
56 |
dl |
1.8 |
* Completion may be due to normal termination, an exception, or |
57 |
|
|
* cancellation -- in all of these cases, this method will return |
58 |
|
|
* <tt>true</tt>. |
59 |
|
|
* |
60 |
|
|
* @return <tt>true</tt> if this task completed. |
61 |
tim |
1.1 |
*/ |
62 |
|
|
boolean isDone(); |
63 |
|
|
} |