AbstractExecutorService (Java SE 9 & JDK 9 ) (original) (raw)
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-java.lang.Runnable-)` 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-java.lang.Runnable-T-)` 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-java.util.concurrent.Callable-)` 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
* #### invokeAny
public <T> T invokeAny([Collection](../../../java/util/Collection.html "interface in java.util")<? extends [Callable](../../../java/util/concurrent/Callable.html "interface in java.util.concurrent")<T>> tasks)
throws [InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang"),
[ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent")
Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.
Specified by:
`[invokeAny](../../../java/util/concurrent/ExecutorService.html#invokeAny-java.util.Collection-)` in interface `[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")`
Type Parameters:
`T` \- the type of the values returned from the tasks
Parameters:
`tasks` \- the collection of tasks
Returns:
the result returned by one of the tasks
Throws:
`[InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")` \- if interrupted while waiting
`[ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent")` \- if no task successfully completes
* #### invokeAny
public <T> T invokeAny([Collection](../../../java/util/Collection.html "interface in java.util")<? extends [Callable](../../../java/util/concurrent/Callable.html "interface in java.util.concurrent")<T>> tasks,
long timeout,
[TimeUnit](../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit)
throws [InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang"),
[ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent"),
[TimeoutException](../../../java/util/concurrent/TimeoutException.html "class in java.util.concurrent")
Executes the given tasks, returning the result of one that has completed successfully (i.e., without throwing an exception), if any do before the given timeout elapses. Upon normal or exceptional return, tasks that have not completed are cancelled. The results of this method are undefined if the given collection is modified while this operation is in progress.
Specified by:
`[invokeAny](../../../java/util/concurrent/ExecutorService.html#invokeAny-java.util.Collection-long-java.util.concurrent.TimeUnit-)` in interface `[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")`
Type Parameters:
`T` \- the type of the values returned from the tasks
Parameters:
`tasks` \- the collection of tasks
`timeout` \- the maximum time to wait
`unit` \- the time unit of the timeout argument
Returns:
the result returned by one of the tasks
Throws:
`[InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")` \- if interrupted while waiting
`[ExecutionException](../../../java/util/concurrent/ExecutionException.html "class in java.util.concurrent")` \- if no task successfully completes
`[TimeoutException](../../../java/util/concurrent/TimeoutException.html "class in java.util.concurrent")` \- if the given timeout elapses before any task successfully completes
* #### invokeAll
public <T> [List](../../../java/util/List.html "interface in java.util")<[Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<T>> invokeAll([Collection](../../../java/util/Collection.html "interface in java.util")<? extends [Callable](../../../java/util/concurrent/Callable.html "interface in java.util.concurrent")<T>> tasks)
throws [InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")
Executes the given tasks, returning a list of Futures holding their status and results when all complete.[Future.isDone()](../../../java/util/concurrent/Future.html#isDone--) is `true` for each element of the returned list. Note that a _completed_ task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.
Specified by:
`[invokeAll](../../../java/util/concurrent/ExecutorService.html#invokeAll-java.util.Collection-)` in interface `[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")`
Type Parameters:
`T` \- the type of the values returned from the tasks
Parameters:
`tasks` \- the collection of tasks
Returns:
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
Throws:
`[InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")` \- if interrupted while waiting, in which case unfinished tasks are cancelled
* #### invokeAll
public <T> [List](../../../java/util/List.html "interface in java.util")<[Future](../../../java/util/concurrent/Future.html "interface in java.util.concurrent")<T>> invokeAll([Collection](../../../java/util/Collection.html "interface in java.util")<? extends [Callable](../../../java/util/concurrent/Callable.html "interface in java.util.concurrent")<T>> tasks,
long timeout,
[TimeUnit](../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit)
throws [InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")
Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first.[Future.isDone()](../../../java/util/concurrent/Future.html#isDone--) is `true` for each element of the returned list. Upon return, tasks that have not completed are cancelled. Note that a _completed_ task could have terminated either normally or by throwing an exception. The results of this method are undefined if the given collection is modified while this operation is in progress.
Specified by:
`[invokeAll](../../../java/util/concurrent/ExecutorService.html#invokeAll-java.util.Collection-long-java.util.concurrent.TimeUnit-)` in interface `[ExecutorService](../../../java/util/concurrent/ExecutorService.html "interface in java.util.concurrent")`
Type Parameters:
`T` \- the type of the values returned from the tasks
Parameters:
`tasks` \- the collection of tasks
`timeout` \- the maximum time to wait
`unit` \- the time unit of the timeout argument
Returns:
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.
Throws:
`[InterruptedException](../../../java/lang/InterruptedException.html "class in java.lang")` \- if interrupted while waiting, in which case unfinished tasks are cancelled