AbstractExecutorService (Java SE 10 & JDK 10 ) (original) (raw)
- java.util.concurrent.AbstractExecutorService
All Implemented Interfaces:
[Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent")
,[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")
Direct Known Subclasses:[ForkJoinPool](../../../java/util/concurrent/ForkJoinPool.html "class in java.util.concurrent")
,[ThreadPoolExecutor](../../../java/util/concurrent/ThreadPoolExecutor.html "class in java.util.concurrent")
public abstract class AbstractExecutorService
extends Object
implements ExecutorService
Provides default implementations of ExecutorService execution methods. This class implements the submit
,invokeAny
and invokeAll
methods using aRunnableFuture returned by newTaskFor
, which defaults to the FutureTask class provided in this package. For example, the implementation of submit(Runnable)
creates an associated RunnableFuture
that is executed and returned. Subclasses may override the newTaskFor
methods to return RunnableFuture
implementations other thanFutureTask
.
Extension example. Here is a sketch of a class that customizes ThreadPoolExecutor to use a CustomTask
class instead of the default FutureTask
:
public class CustomThreadPoolExecutor extends ThreadPoolExecutor { static class CustomTask<V> implements RunnableFuture<V> {...} protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) { return new CustomTask<V>(c); } protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) { return new CustomTask<V>(r, v); } // ... add constructors, etc. }
Since:
1.5
Constructor Summary
Constructors
Constructor Description AbstractExecutorService() Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description protected RunnableFuture newTaskFor(Runnable runnable, T value) Returns a RunnableFuture for the given runnable and default value. protected RunnableFuture newTaskFor(Callable callable) Returns a RunnableFuture for the given callable task. Future<?> submit(Runnable task) Submits a Runnable task for execution and returns a Future representing that task. Future submit(Runnable task, T result) Submits a Runnable task for execution and returns a Future representing that task. Future submit(Callable task) Submits a value-returning task for execution and returns a Future representing the pending results of the task. * ### Methods declared in interface java.util.concurrent.[Executor](../../../java/util/concurrent/Executor.html "interface in java.util.concurrent") `[execute](../../../java/util/concurrent/Executor.html#execute%28java.lang.Runnable%29)` * ### Methods declared in interface java.util.concurrent.[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent") `[awaitTermination](../../../java/util/concurrent/ExecutorService.html#awaitTermination%28long,java.util.concurrent.TimeUnit%29), [invokeAll](../../../java/util/concurrent/ExecutorService.html#invokeAll%28java.util.Collection%29), [invokeAll](../../../java/util/concurrent/ExecutorService.html#invokeAll%28java.util.Collection,long,java.util.concurrent.TimeUnit%29), [invokeAny](../../../java/util/concurrent/ExecutorService.html#invokeAny%28java.util.Collection%29), [invokeAny](../../../java/util/concurrent/ExecutorService.html#invokeAny%28java.util.Collection,long,java.util.concurrent.TimeUnit%29), [isShutdown](../../../java/util/concurrent/ExecutorService.html#isShutdown%28%29), [isTerminated](../../../java/util/concurrent/ExecutorService.html#isTerminated%28%29), [shutdown](../../../java/util/concurrent/ExecutorService.html#shutdown%28%29), [shutdownNow](../../../java/util/concurrent/ExecutorService.html#shutdownNow%28%29)` * ### Methods declared in class java.lang.[Object](../../../java/lang/Object.html "class in java.lang") `[clone](../../../java/lang/Object.html#clone%28%29), [equals](../../../java/lang/Object.html#equals%28java.lang.Object%29), [finalize](../../../java/lang/Object.html#finalize%28%29), [getClass](../../../java/lang/Object.html#getClass%28%29), [hashCode](../../../java/lang/Object.html#hashCode%28%29), [notify](../../../java/lang/Object.html#notify%28%29), [notifyAll](../../../java/lang/Object.html#notifyAll%28%29), [toString](../../../java/lang/Object.html#toString%28%29), [wait](../../../java/lang/Object.html#wait%28%29), [wait](../../../java/lang/Object.html#wait%28long%29), [wait](../../../java/lang/Object.html#wait%28long,int%29)`
Constructor Detail
* #### AbstractExecutorService public AbstractExecutorService()
Method Detail
* #### newTaskFor protected <T> [RunnableFuture](../../../java/util/concurrent/RunnableFuture.html "interface in java.util.concurrent")<T> newTaskFor([Runnable](../../../java/lang/Runnable.html "interface in java.lang") runnable, T value) Returns a `RunnableFuture` for the given runnable and default value. Type Parameters: `T` \- the type of the given value Parameters: `runnable` \- the runnable task being wrapped `value` \- the default value for the returned future Returns: a `RunnableFuture` which, when run, will run the underlying runnable and which, as a `Future`, will yield the given value as its result and provide for cancellation of the underlying task Since: 1.6 * #### newTaskFor protected <T> [RunnableFuture](../../../java/util/concurrent/RunnableFuture.html "interface in java.util.concurrent")<T> newTaskFor([Callable](../../../java/util/concurrent/Callable.html "interface in java.util.concurrent")<T> callable) Returns a `RunnableFuture` for the given callable task. Type Parameters: `T` \- the type of the callable's result Parameters: `callable` \- the callable task being wrapped Returns: a `RunnableFuture` which, when run, will call the underlying callable and which, as a `Future`, will yield the callable's result as its result and provide for cancellation of the underlying task Since: 1.6 * #### submit public [Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<?> submit([Runnable](../../../java/lang/Runnable.html "interface in java.lang") task) Submits a Runnable task for execution and returns a Future representing that task. The Future's `get` method will return `null` upon _successful_ completion. Specified by: `[submit](../../../java/util/concurrent/ExecutorService.html#submit%28java.lang.Runnable%29)` in interface `[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")` Parameters: `task` \- the task to submit Returns: a Future representing pending completion of the task Throws: `[RejectedExecutionException](../../../java/util/concurrent/RejectedExecutionException.html "class in java.util.concurrent")` \- if the task cannot be scheduled for execution `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if the task is null * #### submit public <T> [Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<T> submit([Runnable](../../../java/lang/Runnable.html "interface in java.lang") task, T result) Submits a Runnable task for execution and returns a Future representing that task. The Future's `get` method will return the given result upon successful completion. Specified by: `[submit](../../../java/util/concurrent/ExecutorService.html#submit%28java.lang.Runnable,T%29)` in interface `[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")` Type Parameters: `T` \- the type of the result Parameters: `task` \- the task to submit `result` \- the result to return Returns: a Future representing pending completion of the task Throws: `[RejectedExecutionException](../../../java/util/concurrent/RejectedExecutionException.html "class in java.util.concurrent")` \- if the task cannot be scheduled for execution `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if the task is null * #### submit public <T> [Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<T> submit([Callable](../../../java/util/concurrent/Callable.html "interface in java.util.concurrent")<T> task) Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future's `get` method will return the task's result upon successful completion. If you would like to immediately block waiting for a task, you can use constructions of the form`result = exec.submit(aCallable).get();` Note: The [Executors](../../../java/util/concurrent/Executors.html "class in java.util.concurrent") class includes a set of methods that can convert some other common closure-like objects, for example, [PrivilegedAction](../../../java/security/PrivilegedAction.html "interface in java.security") to[Callable](../../../java/util/concurrent/Callable.html "interface in java.util.concurrent") form so they can be submitted. Specified by: `[submit](../../../java/util/concurrent/ExecutorService.html#submit%28java.util.concurrent.Callable%29)` in interface `[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")` Type Parameters: `T` \- the type of the task's result Parameters: `task` \- the task to submit Returns: a Future representing pending completion of the task Throws: `[RejectedExecutionException](../../../java/util/concurrent/RejectedExecutionException.html "class in java.util.concurrent")` \- if the task cannot be scheduled for execution `[NullPointerException](../../../java/lang/NullPointerException.html "class in java.lang")` \- if the task is null
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2018, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.