1 *java.util.concurrent.FutureTask* *FutureTask* A cancellable asynchronous comput
3 public class FutureTask<V>
4 extends |java.lang.Object|
5 implements |java.util.concurrent.RunnableFuture|
7 |java.util.concurrent.FutureTask_Description|
8 |java.util.concurrent.FutureTask_Fields|
9 |java.util.concurrent.FutureTask_Constructors|
10 |java.util.concurrent.FutureTask_Methods|
12 ================================================================================
14 *java.util.concurrent.FutureTask_Constructors*
15 |java.util.concurrent.FutureTask(Callable<V>)|Creates a FutureTask that will up
16 |java.util.concurrent.FutureTask(Runnable,V)|Creates a FutureTask that will upo
18 *java.util.concurrent.FutureTask_Methods*
19 |java.util.concurrent.FutureTask.cancel(boolean)|
20 |java.util.concurrent.FutureTask.done()|Protected method invoked when this task
21 |java.util.concurrent.FutureTask.get()|
22 |java.util.concurrent.FutureTask.get(long,TimeUnit)|
23 |java.util.concurrent.FutureTask.isCancelled()|
24 |java.util.concurrent.FutureTask.isDone()|
25 |java.util.concurrent.FutureTask.run()|Sets this Future to the result of its co
26 |java.util.concurrent.FutureTask.runAndReset()|Executes the computation without
27 |java.util.concurrent.FutureTask.set(V)|Sets the result of this Future to the g
28 |java.util.concurrent.FutureTask.setException(Throwable)|Causes this future to
30 *java.util.concurrent.FutureTask_Description*
32 A cancellable asynchronous computation. This class provides a base
33 implementation of (|java.util.concurrent.Future|) , with methods to start and
34 cancel a computation, query to see if the computation is complete, and retrieve
35 the result of the computation. The result can only be retrieved when the
36 computation has completed; the get method will block if the computation has not
37 yet completed. Once the computation has completed, the computation cannot be
38 restarted or cancelled.
40 A FutureTask can be used to wrap a (|java.util.concurrent.Callable|) or
41 (|java.lang.Runnable|) object. Because FutureTask implements Runnable, a
42 FutureTask can be submitted to an (|java.util.concurrent.Executor|) for
45 In addition to serving as a standalone class, this class provides protected
46 functionality that may be useful when creating customized task classes.
50 *java.util.concurrent.FutureTask(Callable<V>)*
52 public FutureTask(java.util.concurrent.Callable<V> callable)
54 Creates a FutureTask that will upon running, execute the given Callable.
56 callable - the callable task
58 *java.util.concurrent.FutureTask(Runnable,V)*
61 java.lang.Runnable runnable,
64 Creates a FutureTask that will upon running, execute the given Runnable, and
65 arrange that get will return the given result on successful completion.
67 runnable - the runnable task
68 result - the result to return on successful completion. If you don't need a particular
69 result, consider using constructions of the form: Future<?> f = new
70 FutureTask<Object>(runnable, null)
72 *java.util.concurrent.FutureTask.cancel(boolean)*
74 public boolean cancel(boolean mayInterruptIfRunning)
80 *java.util.concurrent.FutureTask.done()*
84 Protected method invoked when this task transitions to state isDone (whether
85 normally or via cancellation). The default implementation does nothing.
86 Subclasses may override this method to invoke completion callbacks or perform
87 bookkeeping. Note that you can query status inside the implementation of this
88 method to determine whether this task has been cancelled.
92 *java.util.concurrent.FutureTask.get()*
95 throws |java.util.concurrent.ExecutionException|
96 |java.lang.InterruptedException|
102 *java.util.concurrent.FutureTask.get(long,TimeUnit)*
106 java.util.concurrent.TimeUnit unit)
107 throws |java.util.concurrent.ExecutionException|
108 |java.lang.InterruptedException|
109 |java.util.concurrent.TimeoutException|
115 *java.util.concurrent.FutureTask.isCancelled()*
117 public boolean isCancelled()
123 *java.util.concurrent.FutureTask.isDone()*
125 public boolean isDone()
131 *java.util.concurrent.FutureTask.run()*
135 Sets this Future to the result of its computation unless it has been cancelled.
139 *java.util.concurrent.FutureTask.runAndReset()*
141 protected boolean runAndReset()
143 Executes the computation without setting its result, and then resets this
144 Future to initial state, failing to do so if the computation encounters an
145 exception or is cancelled. This is designed for use with tasks that
146 intrinsically execute more than once.
150 Returns: true if successfully run and reset
152 *java.util.concurrent.FutureTask.set(V)*
154 protected void set(V v)
156 Sets the result of this Future to the given value unless this future has
157 already been set or has been cancelled. This method is invoked internally by
158 the run method upon successful completion of the computation.
163 *java.util.concurrent.FutureTask.setException(Throwable)*
165 protected void setException(java.lang.Throwable t)
167 Causes this future to report an ExecutionException with the given throwable as
168 its cause, unless this Future has already been set or has been cancelled. This
169 method is invoked internally by the run method upon failure of the computation.
172 t - the cause of failure