20 |
|
* to return other <tt>RunnableFuture</tt> implementations than |
21 |
|
* <tt>FutureTask</tt>. |
22 |
|
* |
23 |
+ |
* <p> <b>Extension example</b>. Here is a sketch of a class |
24 |
+ |
* that customizes {@link ThreadPoolExecutor} to use |
25 |
+ |
* a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>: |
26 |
+ |
* <pre> |
27 |
+ |
* public class CustomThreadPoolExecutor extends ThreadPoolExecutor { |
28 |
+ |
* |
29 |
+ |
* static class CustomTask<V> implements RunnableFuture<V> {...} |
30 |
+ |
* |
31 |
+ |
* <V> protected RunnableFuture<V> newTaskFor(Callable<V> c) { |
32 |
+ |
* return new CustomTask<V>(c); |
33 |
+ |
* } |
34 |
+ |
* <V> protected RunnableFuture<V> newTaskFor(Runnable r, V v) { |
35 |
+ |
* return new CustomTask<V>(r, v); |
36 |
+ |
* } |
37 |
+ |
* // ... add constructors, etc. |
38 |
+ |
* } |
39 |
+ |
* </pre> |
40 |
|
* @since 1.5 |
41 |
|
* @author Doug Lea |
42 |
|
*/ |
47 |
|
* value. |
48 |
|
* @param runnable the runnable task being wrapped |
49 |
|
* @param value the default value for the returned future |
50 |
< |
* @return a RunnableFuture which when run will run the underlying |
51 |
< |
* runnable and which, as a Future, will yield the given value as its result |
52 |
< |
* and provide for cancellation of the underlying task. |
50 |
> |
* @return a <tt>RunnableFuture</tt> which when run will run the |
51 |
> |
* underlying runnable and which, as a <tt>Future</tt>, will yield |
52 |
> |
* the given value as its result and provide for cancellation of |
53 |
> |
* the underlying task. |
54 |
> |
* @since 1.6 |
55 |
|
*/ |
56 |
|
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) { |
57 |
|
return new FutureTask<T>(runnable, value); |
60 |
|
/** |
61 |
|
* Returns a <tt>RunnableFuture</tt> for the given callable task. |
62 |
|
* @param callable the callable task being wrapped |
63 |
< |
* @return a RunnableFuture which when run will call the underlying |
64 |
< |
* callable and which, as a Future, will yield the callable's result |
65 |
< |
* as its result and provide for cancellation of the underlying task. |
63 |
> |
* @return a <tt>RunnableFuture</tt> which when run will call the |
64 |
> |
* underlying callable and which, as a <tt>Future</tt>, will yield |
65 |
> |
* the callable's result as its result and provide for |
66 |
> |
* cancellation of the underlying task. |
67 |
> |
* @since 1.6 |
68 |
|
*/ |
69 |
|
protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) { |
70 |
|
return new FutureTask<T>(callable); |