53 |
|
* Creates a new CancellableTask which invokes the given |
54 |
|
* <tt>Runnable</tt> when executed. |
55 |
|
* @param r the runnable action |
56 |
+ |
* @throws NullPointerException if runnable is null |
57 |
|
*/ |
58 |
|
public CancellableTask(Runnable r) { |
59 |
+ |
if (r == null) |
60 |
+ |
throw new NullPointerException(); |
61 |
|
this.runnable = r; |
62 |
|
} |
63 |
|
|
156 |
|
} |
157 |
|
|
158 |
|
/** |
159 |
< |
* Reset the run state of this task to its initial state. |
159 |
> |
* Reset the run state of this task to its initial state unless |
160 |
> |
* it has been cancelled. (Note that a cancelled task cannot be |
161 |
> |
* reset.) |
162 |
> |
* @return true if successful |
163 |
|
*/ |
164 |
< |
protected void reset() { |
165 |
< |
runnerUpdater.set(this, null); |
164 |
> |
protected boolean reset() { |
165 |
> |
for (;;) { |
166 |
> |
Object r = runner; |
167 |
> |
if (r == CANCELLED) |
168 |
> |
return false; |
169 |
> |
if (runnerUpdater.compareAndSet(this, r, null)) |
170 |
> |
return true; |
171 |
> |
} |
172 |
|
} |
173 |
|
|
174 |
|
/** |