Interface ListeningExecutorService
- 
- All Superinterfaces:
 Executor,ExecutorService
- All Known Subinterfaces:
 ListeningScheduledExecutorService
- All Known Implementing Classes:
 AbstractListeningExecutorService,ForwardingListeningExecutorService
@DoNotMock("Use TestingExecutors.sameThreadScheduledExecutor, or wrap a real Executor from java.util.concurrent.Executors with MoreExecutors.listeningDecorator") @GwtIncompatible public interface ListeningExecutorService extends ExecutorService
AnExecutorServicethat returnsListenableFutureinstances. To create an instance from an existingExecutorService, callMoreExecutors.listeningDecorator(ExecutorService).- Since:
 - 10.0
 - Author:
 - Chris Povirk
 
 
- 
- 
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description <T extends @Nullable Object>
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 extends @Nullable Object>
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.ListenableFuture<?>submit(Runnable task)Submits a Runnable task for execution and returns a Future representing that task.<T extends @Nullable Object>
ListenableFuture<T>submit(Runnable task, T result)Submits a Runnable task for execution and returns a Future representing that task.<T extends @Nullable Object>
ListenableFuture<T>submit(Callable<T> task)Submits a value-returning task for execution and returns a Future representing the pending results of the task.- 
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow 
 - 
 
 - 
 
- 
- 
Method Detail
- 
submit
<T extends @Nullable Object> ListenableFuture<T> submit(Callable<T> task)
Description copied from interface:java.util.concurrent.ExecutorServiceSubmits a value-returning task for execution and returns a Future representing the pending results of the task. The Future'sgetmethod 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
Executorsclass includes a set of methods that can convert some other common closure-like objects, for example,PrivilegedActiontoCallableform so they can be submitted.- Specified by:
 submitin interfaceExecutorService- Type Parameters:
 T- the type of the task's result- Parameters:
 task- the task to submit- Returns:
 - a 
ListenableFuturerepresenting pending completion of the task - Throws:
 RejectedExecutionException- if the task cannot be scheduled for execution
 
- 
submit
ListenableFuture<?> submit(Runnable task)
Description copied from interface:java.util.concurrent.ExecutorServiceSubmits a Runnable task for execution and returns a Future representing that task. The Future'sgetmethod will returnnullupon successful completion.- Specified by:
 submitin interfaceExecutorService- Parameters:
 task- the task to submit- Returns:
 - a 
ListenableFuturerepresenting pending completion of the task - Throws:
 RejectedExecutionException- if the task cannot be scheduled for execution
 
- 
submit
<T extends @Nullable Object> ListenableFuture<T> submit(Runnable task, T result)
Description copied from interface:java.util.concurrent.ExecutorServiceSubmits a Runnable task for execution and returns a Future representing that task. The Future'sgetmethod will return the given result upon successful completion.- Specified by:
 submitin interfaceExecutorService- Type Parameters:
 T- the type of the result- Parameters:
 task- the task to submitresult- the result to return- Returns:
 - a 
ListenableFuturerepresenting pending completion of the task - Throws:
 RejectedExecutionException- if the task cannot be scheduled for execution
 
- 
invokeAll
<T extends @Nullable Object> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
Executes the given tasks, returning a list of Futures holding their status and results when all complete.Future.isDone()istruefor 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
ListenableFutureinstances. The easiest way to obtain aList<ListenableFuture<T>>from this method is an unchecked (but safe) cast:@SuppressWarnings("unchecked") // guaranteed by invokeAll contractList<ListenableFuture<T>> futures = (List) executor.invokeAll(tasks);- Specified by:
 invokeAllin interfaceExecutorService- Type Parameters:
 T- the type of the values returned from the tasks- Parameters:
 tasks- the collection of tasks- Returns:
 - A list of 
ListenableFutureinstances representing the tasks, in the same sequential order as produced by the iterator for the given task list, each of which has completed. - Throws:
 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
 
- 
invokeAll
<T extends @Nullable Object> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException
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()istruefor 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
ListenableFutureinstances. The easiest way to obtain aList<ListenableFuture<T>>from this method is an unchecked (but safe) cast:@SuppressWarnings("unchecked") // guaranteed by invokeAll contractList<ListenableFuture<T>> futures = (List) executor.invokeAll(tasks, timeout, unit);- Specified by:
 invokeAllin interfaceExecutorService- 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 
ListenableFutureinstances 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:
 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
 
 - 
 
 -