Interface ListeningExecutorService
- All Superinterfaces:
AutoCloseable
,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
An
ExecutorService
that returns ListenableFuture
instances. To create an instance
from an existing ExecutorService
, call MoreExecutors.listeningDecorator(ExecutorService)
.- Since:
- 10.0
- Author:
- Chris Povirk
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
awaitTermination
(Duration timeout) Duration-based overload ofExecutorService.awaitTermination(long, TimeUnit)
.invokeAll
(Collection<? extends Callable<T>> tasks) invokeAll
(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) invokeAll
(Collection<? extends Callable<T>> tasks, Duration timeout) Duration-based overload ofinvokeAll(Collection, long, TimeUnit)
.invokeAny
(Collection<? extends Callable<T>> tasks, Duration timeout) Duration-based overload ofExecutorService.invokeAny(Collection, long, TimeUnit)
.<T extends @Nullable Object>
ListenableFuture<T> <T extends @Nullable Object>
ListenableFuture<T> Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, close, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow
-
Method Details
-
submit
- Specified by:
submit
in interfaceExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
submit
- Specified by:
submit
in interfaceExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
submit
- Specified by:
submit
in interfaceExecutorService
- Returns:
- a
ListenableFuture
representing pending completion of the task
-
invokeAll
<T extends @Nullable Object> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException 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:
invokeAll
in interfaceExecutorService
- 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.
-
invokeAll
<T extends @Nullable Object> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException 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:
invokeAll
in interfaceExecutorService
- 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.
-
invokeAll
default <T extends @Nullable Object> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, Duration timeout) throws InterruptedException Duration-based overload ofinvokeAll(Collection, long, TimeUnit)
.- Throws:
InterruptedException
- Since:
- 32.1.0
-
invokeAny
default <T extends @Nullable Object> T invokeAny(Collection<? extends Callable<T>> tasks, Duration timeout) throws InterruptedException, ExecutionException, TimeoutException Duration-based overload ofExecutorService.invokeAny(Collection, long, TimeUnit)
.- Throws:
InterruptedException
ExecutionException
TimeoutException
- Since:
- 32.1.0
-
awaitTermination
Duration-based overload ofExecutorService.awaitTermination(long, TimeUnit)
.- Throws:
InterruptedException
- Since:
- 32.1.0
-