@GwtIncompatible public interface ListeningExecutorService extends ExecutorService
ExecutorService
that returns ListenableFuture
instances. To create an instance
from an existing ExecutorService
, call MoreExecutors.listeningDecorator(ExecutorService)
.Modifier and Type | Method and Description |
---|---|
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks)
Executes the given tasks, returning a list of Futures holding
their status and results when all complete.
|
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit)
Executes the given tasks, returning a list of Futures holding
their status and results
when all complete or the timeout expires, whichever happens first.
|
<T> ListenableFuture<T> |
submit(Callable<T> task)
Submits a value-returning task for execution and returns a
Future representing the pending results of the task.
|
ListenableFuture<?> |
submit(Runnable task)
Submits a Runnable task for execution and returns a Future
representing that task.
|
<T> ListenableFuture<T> |
submit(Runnable task,
T result)
Submits a Runnable task for execution and returns a Future
representing that task.
|
awaitTermination, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow
<T> ListenableFuture<T> submit(Callable<T> task)
java.util.concurrent.ExecutorService
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
class includes a set of methods
that can convert some other common closure-like objects,
for example, PrivilegedAction
to
Callable
form so they can be submitted.
submit
in interface ExecutorService
T
- the type of the task's resulttask
- the task to submitListenableFuture
representing pending completion of the taskRejectedExecutionException
- if the task cannot be
scheduled for executionListenableFuture<?> submit(Runnable task)
java.util.concurrent.ExecutorService
get
method will
return null
upon successful completion.submit
in interface ExecutorService
task
- the task to submitListenableFuture
representing pending completion of the taskRejectedExecutionException
- if the task cannot be
scheduled for execution<T> ListenableFuture<T> submit(Runnable task, T result)
java.util.concurrent.ExecutorService
get
method will
return the given result upon successful completion.submit
in interface ExecutorService
T
- the type of the resulttask
- the task to submitresult
- the result to returnListenableFuture
representing pending completion of the taskRejectedExecutionException
- if the task cannot be
scheduled for execution<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
Future.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.
All elements in the returned list must be ListenableFuture
instances. The easiest
way to obtain a List<ListenableFuture<T>>
from this method is an unchecked (but safe)
cast:
@SuppressWarnings("unchecked") // guaranteed by invokeAll contract
List<ListenableFuture<T>> futures = (List) executor.invokeAll(tasks);
invokeAll
in interface ExecutorService
T
- the type of the values returned from the taskstasks
- the collection of tasksListenableFuture
instances representing the tasks, in the same
sequential order as produced by the iterator for the given task list, each of which has
completed.RejectedExecutionException
- if any task cannot be
scheduled for executionNullPointerException
- if any task is nullInterruptedException
- if interrupted while waiting, in
which case unfinished tasks are cancelled<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
Future.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.
All elements in the returned list must be ListenableFuture
instances. The easiest
way to obtain a List<ListenableFuture<T>>
from this method is an unchecked (but safe)
cast:
@SuppressWarnings("unchecked") // guaranteed by invokeAll contract
List<ListenableFuture<T>> futures = (List) executor.invokeAll(tasks, timeout, unit);
invokeAll
in interface ExecutorService
T
- the type of the values returned from the taskstasks
- the collection of taskstimeout
- the maximum time to waitunit
- the time unit of the timeout argumentListenableFuture
instances 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.RejectedExecutionException
- if any task cannot be scheduled
for executionNullPointerException
- if any task is nullInterruptedException
- if interrupted while waiting, in
which case unfinished tasks are cancelledCopyright © 2010–2018. All rights reserved.