Interface ListeningExecutorService
-
- All Superinterfaces:
,
- All Known Subinterfaces:
ListeningScheduledExecutorService
- All Known Implementing Classes:
AbstractListeningExecutorService
,ForwardingListeningExecutorService
("Use TestingExecutors.sameThreadScheduledExecutor, or wrap a real Executor from java.util.concurrent.Executors with MoreExecutors.listeningDecorator") @GwtIncompatible public interface ListeningExecutorService extends
An that returnsListenableFuture
instances. To create an instance from an existing , callMoreExecutors.listeningDecorator(ExecutorService)
.- Since:
- 10.0
- Author:
- Chris Povirk
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> <<T>>
<? extends <T>> tasks)
Executes the given tasks, returning a list of Futures holding their status and results when all complete.<T> <<T>>
<? extends <T>> tasks, long timeout, 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.ListenableFuture<?>
task)
Submits a Runnable task for execution and returns a Future representing that task.<T> ListenableFuture<T>
task, T result)
Submits a Runnable task for execution and returns a Future representing that task.<T> ListenableFuture<T>
<T> task)
Submits a value-returning task for execution and returns a Future representing the pending results of the task.
-
-
-
Method Detail
-
submit
<T> <T> task)
Description copied from interface:Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future'sget
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 class includes a set of methods that can convert some other common closure-like objects, for example, to form so they can be submitted.
- Specified by:
in interface
- Type Parameters:
T
- the type of the task's result- Parameters:
task
- the task to submit- Returns:
- a
ListenableFuture
representing pending completion of the task - Throws:
- if the task cannot be scheduled for execution
-
submit
task)
Description copied from interface:Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will returnnull
upon successful completion.- Specified by:
in interface
- Parameters:
task
- the task to submit- Returns:
- a
ListenableFuture
representing pending completion of the task - Throws:
- if the task cannot be scheduled for execution
-
submit
<T> task, T result)
Description copied from interface:Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will return the given result upon successful completion.- Specified by:
in interface
- Type Parameters:
T
- the type of the result- Parameters:
task
- the task to submitresult
- the result to return- Returns:
- a
ListenableFuture
representing pending completion of the task - Throws:
- if the task cannot be scheduled for execution
-
invokeAll
<T> <<T>> <? extends <T>> tasks) throws
Executes the given tasks, returning a list of Futures holding their status and results when all complete. istrue
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 aList<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);
- Specified by:
in interface
- Type Parameters:
T
- the type of the values returned from the tasks- Parameters:
tasks
- the collection of tasks- Returns:
- A list of
ListenableFuture
instances representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed. - Throws:
- if any task cannot be scheduled for execution
- if any task is null
- if interrupted while waiting, in which case unfinished tasks are cancelled
-
invokeAll
<T> <<T>> <? extends <T>> tasks, long timeout, unit) throws
Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first. istrue
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 aList<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);
- Specified by:
in interface
- Type Parameters:
T
- the type of the values returned from the tasks- Parameters:
tasks
- the collection of taskstimeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
- a list of
ListenableFuture
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. - Throws:
- if any task cannot be scheduled for execution
- if any task is null
- if interrupted while waiting, in which case unfinished tasks are cancelled
-
-