< prev index next >

src/java.base/share/classes/java/util/concurrent/AbstractExecutorService.java

Print this page




  60  * <pre> {@code
  61  * public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
  62  *
  63  *   static class CustomTask<V> implements RunnableFuture<V> {...}
  64  *
  65  *   protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
  66  *       return new CustomTask<V>(c);
  67  *   }
  68  *   protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) {
  69  *       return new CustomTask<V>(r, v);
  70  *   }
  71  *   // ... add constructors, etc.
  72  * }}</pre>
  73  *
  74  * @since 1.5
  75  * @author Doug Lea
  76  */
  77 public abstract class AbstractExecutorService implements ExecutorService {
  78 
  79     /**





  80      * Returns a {@code RunnableFuture} for the given runnable and default
  81      * value.
  82      *
  83      * @param runnable the runnable task being wrapped
  84      * @param value the default value for the returned future
  85      * @param <T> the type of the given value
  86      * @return a {@code RunnableFuture} which, when run, will run the
  87      * underlying runnable and which, as a {@code Future}, will yield
  88      * the given value as its result and provide for cancellation of
  89      * the underlying task
  90      * @since 1.6
  91      */
  92     protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
  93         return new FutureTask<T>(runnable, value);
  94     }
  95 
  96     /**
  97      * Returns a {@code RunnableFuture} for the given callable task.
  98      *
  99      * @param callable the callable task being wrapped




  60  * <pre> {@code
  61  * public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
  62  *
  63  *   static class CustomTask<V> implements RunnableFuture<V> {...}
  64  *
  65  *   protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
  66  *       return new CustomTask<V>(c);
  67  *   }
  68  *   protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) {
  69  *       return new CustomTask<V>(r, v);
  70  *   }
  71  *   // ... add constructors, etc.
  72  * }}</pre>
  73  *
  74  * @since 1.5
  75  * @author Doug Lea
  76  */
  77 public abstract class AbstractExecutorService implements ExecutorService {
  78 
  79     /**
  80      * Constructor for subclasses to call.
  81      */
  82     public AbstractExecutorService() {}
  83 
  84     /**
  85      * Returns a {@code RunnableFuture} for the given runnable and default
  86      * value.
  87      *
  88      * @param runnable the runnable task being wrapped
  89      * @param value the default value for the returned future
  90      * @param <T> the type of the given value
  91      * @return a {@code RunnableFuture} which, when run, will run the
  92      * underlying runnable and which, as a {@code Future}, will yield
  93      * the given value as its result and provide for cancellation of
  94      * the underlying task
  95      * @since 1.6
  96      */
  97     protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
  98         return new FutureTask<T>(runnable, value);
  99     }
 100 
 101     /**
 102      * Returns a {@code RunnableFuture} for the given callable task.
 103      *
 104      * @param callable the callable task being wrapped


< prev index next >