< prev index next >

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

Print this page
8234131: Miscellaneous changes imported from jsr166 CVS 2021-01
Reviewed-by: martin


  37 
  38 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  39 
  40 import java.util.ArrayList;
  41 import java.util.Collection;
  42 import java.util.Iterator;
  43 import java.util.List;
  44 
  45 /**
  46  * Provides default implementations of {@link ExecutorService}
  47  * execution methods. This class implements the {@code submit},
  48  * {@code invokeAny} and {@code invokeAll} methods using a
  49  * {@link RunnableFuture} returned by {@code newTaskFor}, which defaults
  50  * to the {@link FutureTask} class provided in this package.  For example,
  51  * the implementation of {@code submit(Runnable)} creates an
  52  * associated {@code RunnableFuture} that is executed and
  53  * returned. Subclasses may override the {@code newTaskFor} methods
  54  * to return {@code RunnableFuture} implementations other than
  55  * {@code FutureTask}.
  56  *
  57  * <p><b>Extension example</b>. Here is a sketch of a class
  58  * that customizes {@link ThreadPoolExecutor} to use
  59  * a {@code CustomTask} class instead of the default {@code FutureTask}:
  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 




  37 
  38 import static java.util.concurrent.TimeUnit.NANOSECONDS;
  39 
  40 import java.util.ArrayList;
  41 import java.util.Collection;
  42 import java.util.Iterator;
  43 import java.util.List;
  44 
  45 /**
  46  * Provides default implementations of {@link ExecutorService}
  47  * execution methods. This class implements the {@code submit},
  48  * {@code invokeAny} and {@code invokeAll} methods using a
  49  * {@link RunnableFuture} returned by {@code newTaskFor}, which defaults
  50  * to the {@link FutureTask} class provided in this package.  For example,
  51  * the implementation of {@code submit(Runnable)} creates an
  52  * associated {@code RunnableFuture} that is executed and
  53  * returned. Subclasses may override the {@code newTaskFor} methods
  54  * to return {@code RunnableFuture} implementations other than
  55  * {@code FutureTask}.
  56  *
  57  * <p><b>Extension example.</b> Here is a sketch of a class
  58  * that customizes {@link ThreadPoolExecutor} to use
  59  * a {@code CustomTask} class instead of the default {@code FutureTask}:
  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 


< prev index next >