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