23 |
|
* |
24 |
|
* @since 1.5 |
25 |
|
* @author Doug Lea |
26 |
+ |
* @param <V> The result type returned by this Future |
27 |
|
*/ |
28 |
|
public class FutureTask<V> extends CancellableTask implements Future<V> { |
29 |
|
|
30 |
+ |
/** |
31 |
+ |
* Callable created in FutureTask(runnable, result) constructor |
32 |
+ |
*/ |
33 |
+ |
private static class RunnableAsCallable<V> implements Callable<V> { |
34 |
+ |
private final Runnable runnable; |
35 |
+ |
private final V result; |
36 |
+ |
RunnableAsCallable(Runnable runnable, V result) { |
37 |
+ |
this.runnable = runnable; |
38 |
+ |
this.result = result; |
39 |
+ |
} |
40 |
+ |
public V call() { |
41 |
+ |
runnable.run(); |
42 |
+ |
return result; |
43 |
+ |
} |
44 |
+ |
} |
45 |
+ |
|
46 |
|
/** |
47 |
|
* Constructs a <tt>FutureTask</tt> that will upon running, execute the |
48 |
|
* given <tt>Callable</tt>. |
74 |
|
if (runnable == null) |
75 |
|
throw new NullPointerException(); |
76 |
|
setRunnable(new InnerCancellableFuture<V> |
77 |
< |
(new Callable<V>() { |
61 |
< |
public V call() { |
62 |
< |
runnable.run(); |
63 |
< |
return result; |
64 |
< |
} |
65 |
< |
})); |
77 |
> |
(new RunnableAsCallable<V>(runnable, result))); |
78 |
|
} |
79 |
|
|
80 |
|
/** |