AbstractExecutorService
abstract class AbstractExecutorService : ExecutorService
Known Indirect Subclasses
|
Provides default implementations of ExecutorService
execution methods. This class implements the submit
, invokeAny
and invokeAll
methods using a RunnableFuture
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 than FutureTask
.
Extension example. Here is a sketch of a class that customizes ThreadPoolExecutor
to use a CustomTask
class instead of the default FutureTask
:
<code>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.
}</code>
Summary
Public constructors |
Constructor for subclasses to call.
|
Protected methods |
open RunnableFuture<T>! |
Returns a RunnableFuture for the given runnable and default value.
|
open RunnableFuture<T>! |
Returns a RunnableFuture for the given callable task.
|
Inherited functions |
From class ExecutorService
Boolean |
awaitTermination(timeout: Long, unit: TimeUnit!)
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
|
Unit |
close()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. This method waits until all tasks have completed execution and the executor has terminated.
If interrupted while waiting, this method stops all executing tasks as if by invoking shutdownNow() . It then continues to wait until all actively executing tasks have completed. Tasks that were awaiting execution are not executed. The interrupt status will be re-asserted before this method returns.
If already terminated, invoking this method has no effect.
|
Boolean |
isShutdown()
Returns true if this executor has been shut down.
|
Boolean |
isTerminated()
Returns true if all tasks have completed following shut down. Note that isTerminated is never true unless either shutdown or shutdownNow was called first.
|
Unit |
shutdown()
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. Invocation has no additional effect if already shut down.
This method does not wait for previously submitted tasks to complete execution. Use awaitTermination to do that.
|
MutableList<Runnable!>! |
shutdownNow()
Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
This method does not wait for actively executing tasks to terminate. Use awaitTermination to do that.
There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. For example, typical implementations will cancel via Thread.interrupt , so any task that fails to respond to interrupts may never terminate.
|
|
From class Executor
Unit |
execute(command: Runnable!)
Executes the given command at some time in the future. The command may execute in a new thread, in a pooled thread, or in the calling thread, at the discretion of the Executor implementation.
|
|
Public constructors
AbstractExecutorService
AbstractExecutorService()
Constructor for subclasses to call.
Public methods
invokeAll
open fun <T : Any!> invokeAll(tasks: MutableCollection<out Callable<T>!>!): MutableList<Future<T>!>!
Parameters |
tasks |
MutableCollection<out Callable<T>!>!: the collection of tasks |
<T> |
the type of the values returned from the tasks |
Return |
MutableList<Future<T>!>! |
a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed |
Exceptions |
java.lang.InterruptedException |
if interrupted while waiting, in which case unfinished tasks are cancelled |
java.lang.NullPointerException |
if tasks or any of its elements are null |
java.util.concurrent.RejectedExecutionException |
if any task cannot be scheduled for execution |
invokeAll
open fun <T : Any!> invokeAll(
tasks: MutableCollection<out Callable<T>!>!,
timeout: Long,
unit: TimeUnit!
): MutableList<Future<T>!>!
Parameters |
tasks |
MutableCollection<out Callable<T>!>!: the collection of tasks |
timeout |
Long: the maximum time to wait |
unit |
TimeUnit!: the time unit of the timeout argument |
<T> |
the type of the values returned from the tasks |
Return |
MutableList<Future<T>!>! |
a list of Futures representing the tasks, in the same sequential order as produced by the iterator for the given task list. If the operation did not time out, each task will have completed. If it did time out, some of these tasks will not have completed. |
Exceptions |
java.lang.InterruptedException |
if interrupted while waiting, in which case unfinished tasks are cancelled |
java.lang.NullPointerException |
if tasks, any of its elements, or unit are null |
java.util.concurrent.RejectedExecutionException |
if any task cannot be scheduled for execution |
invokeAny
open fun <T : Any!> invokeAny(tasks: MutableCollection<out Callable<T>!>!): T
Parameters |
tasks |
MutableCollection<out Callable<T>!>!: the collection of tasks |
<T> |
the type of the values returned from the tasks |
Return |
T |
the result returned by one of the tasks |
Exceptions |
java.lang.InterruptedException |
if interrupted while waiting |
java.lang.NullPointerException |
if tasks or any element task subject to execution is null |
java.lang.IllegalArgumentException |
if tasks is empty |
java.util.concurrent.ExecutionException |
if no task successfully completes |
java.util.concurrent.RejectedExecutionException |
if tasks cannot be scheduled for execution |
invokeAny
open fun <T : Any!> invokeAny(
tasks: MutableCollection<out Callable<T>!>!,
timeout: Long,
unit: TimeUnit!
): T
Parameters |
tasks |
MutableCollection<out Callable<T>!>!: the collection of tasks |
timeout |
Long: the maximum time to wait |
unit |
TimeUnit!: the time unit of the timeout argument |
<T> |
the type of the values returned from the tasks |
Return |
T |
the result returned by one of the tasks |
Exceptions |
java.lang.InterruptedException |
if interrupted while waiting |
java.lang.NullPointerException |
if tasks, or unit, or any element task subject to execution is null |
java.util.concurrent.TimeoutException |
if the given timeout elapses before any task successfully completes |
java.util.concurrent.ExecutionException |
if no task successfully completes |
java.util.concurrent.RejectedExecutionException |
if tasks cannot be scheduled for execution |
submit
open fun submit(task: Runnable!): Future<*>!
Parameters |
task |
Runnable!: the task to submit |
Return |
Future<*>! |
a Future representing pending completion of the task |
Exceptions |
java.util.concurrent.RejectedExecutionException |
if the task cannot be scheduled for execution |
java.lang.NullPointerException |
if the task is null |
submit
open fun <T : Any!> submit(
task: Runnable!,
result: T
): Future<T>!
Parameters |
task |
Runnable!: the task to submit |
result |
T: the result to return |
<T> |
the type of the result |
Return |
Future<T>! |
a Future representing pending completion of the task |
Exceptions |
java.util.concurrent.RejectedExecutionException |
if the task cannot be scheduled for execution |
java.lang.NullPointerException |
if the task is null |
submit
open fun <T : Any!> submit(task: Callable<T>!): Future<T>!
Parameters |
task |
Callable<T>!: the task to submit |
<T> |
the type of the task's result |
Return |
Future<T>! |
a Future representing pending completion of the task |
Exceptions |
java.util.concurrent.RejectedExecutionException |
if the task cannot be scheduled for execution |
java.lang.NullPointerException |
if the task is null |
Protected methods
newTaskFor
protected open fun <T : Any!> newTaskFor(
runnable: Runnable!,
value: T
): RunnableFuture<T>!
Returns a RunnableFuture
for the given runnable and default value.
Parameters |
runnable |
Runnable!: the runnable task being wrapped |
value |
T: the default value for the returned future |
<T> |
the type of the given value |
Return |
RunnableFuture<T>! |
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 |
newTaskFor
protected open fun <T : Any!> newTaskFor(callable: Callable<T>!): RunnableFuture<T>!
Returns a RunnableFuture
for the given callable task.
Parameters |
callable |
Callable<T>!: the callable task being wrapped |
<T> |
the type of the callable's result |
Return |
RunnableFuture<T>! |
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 |