12 |
|
* framework. In addition to serving as a standalone class, this |
13 |
|
* provides <tt>protected</tt> functionality that may be useful when |
14 |
|
* creating customized task classes. |
15 |
+ |
* @since 1.5 |
16 |
+ |
* @author Doug Lea |
17 |
|
*/ |
18 |
|
|
19 |
|
public class CancellableTask implements Cancellable, Runnable { |
27 |
|
*/ |
28 |
|
private volatile Object runner; |
29 |
|
|
30 |
< |
/* |
30 |
> |
/** |
31 |
|
* Special value for "runner" indicating task is completed |
32 |
|
*/ |
33 |
|
private static final Object DONE = new Object(); |
34 |
|
|
35 |
< |
/* |
35 |
> |
/** |
36 |
|
* Special value for "runner" indicating task is cancelled |
37 |
|
*/ |
38 |
|
private static final Object CANCELLED = new Object(); |
48 |
|
/** |
49 |
|
* Creates a new CancellableTask which invokes the given |
50 |
|
* <tt>Runnable</tt> when executed. |
51 |
+ |
* @param r the runnable action |
52 |
|
*/ |
53 |
|
public CancellableTask(Runnable r) { |
54 |
|
this.runnable = r; |
92 |
|
|
93 |
|
/** |
94 |
|
* Return the Runnable forming the basis of this task. |
95 |
+ |
* @return the runnable action |
96 |
|
*/ |
97 |
|
protected Runnable getRunnable() { |
98 |
|
return runnable; |
100 |
|
|
101 |
|
/** |
102 |
|
* Set the Runnable forming the basis of this task. |
103 |
+ |
* @param r the runnable action |
104 |
|
*/ |
105 |
|
protected void setRunnable(Runnable r) { |
106 |
|
runnable = r; |
159 |
|
private final Condition accessible = lock.newCondition(); |
160 |
|
private V result; |
161 |
|
private Throwable exception; |
162 |
+ |
|
163 |
+ |
/** |
164 |
+ |
* Create an InnerCancellableFuture that will execute the |
165 |
+ |
* given callable. |
166 |
+ |
* @param callable the function to execute |
167 |
+ |
*/ |
168 |
|
protected InnerCancellableFuture(Callable<V> callable) { |
169 |
|
this.callable = callable; |
170 |
|
} |