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 |
dl |
1.3 |
* 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 |
tim |
1.1 |
* |
15 |
|
|
* @since 1.5 |
16 |
|
|
* |
17 |
|
|
* @spec JSR-166 |
18 |
dl |
1.5 |
* @revised $Date: 2003/06/07 19:54:10 $ |
19 |
|
|
* @editor $Author: jozart $ |
20 |
tim |
1.1 |
*/ |
21 |
|
|
public interface Cancellable { |
22 |
|
|
|
23 |
|
|
/** |
24 |
dl |
1.5 |
* Attempts to cancel execution of this task. This attempt will |
25 |
|
|
* fail if the task has already completed or could not be |
26 |
|
|
* cancelled for some other reason. If successful, and this task |
27 |
|
|
* has not started when <tt>cancel</tt> is called, this task will |
28 |
|
|
* never run. If the task has already started, then the |
29 |
|
|
* <tt>interruptIfRunning</tt> parameter determines whether the |
30 |
|
|
* thread executing this task should be interrupted in an attempt |
31 |
|
|
* to stop the task. |
32 |
tim |
1.1 |
* |
33 |
jozart |
1.4 |
* @param mayInterruptIfRunning <tt>true</tt> if the thread executing this |
34 |
tim |
1.1 |
* task should be interrupted; otherwise, in-progress tasks are allowed |
35 |
|
|
* to complete |
36 |
dl |
1.5 |
* @return <tt>false</tt> if the task could not be cancelled, |
37 |
|
|
* typically because is has already completed normally; |
38 |
|
|
* <tt>true</tt> otherwise |
39 |
tim |
1.1 |
*/ |
40 |
|
|
boolean cancel(boolean mayInterruptIfRunning); |
41 |
|
|
|
42 |
|
|
/** |
43 |
|
|
* Returns <tt>true</tt> if this task was cancelled before it completed |
44 |
|
|
* normally. |
45 |
|
|
* |
46 |
|
|
* @return <tt>true</tt> if task was cancelled before it completed |
47 |
|
|
*/ |
48 |
|
|
boolean isCancelled(); |
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* Returns <tt>true</tt> if this task ran to completion or was cancelled. |
52 |
|
|
* |
53 |
|
|
* @return <tt>true</tt> if task completed normally or was cancelled |
54 |
|
|
*/ |
55 |
|
|
boolean isDone(); |
56 |
|
|
} |