Class ExecutionSequencer
- java.lang.Object
-
- com.google.common.util.concurrent.ExecutionSequencer
-
@Beta public final class ExecutionSequencer extends java.lang.Object
Serializes execution of a set of operations. This class guarantees that a submitted callable will not be called before previously submitted callables (and anyFutures returned from them) have completed.This class implements a superset of the behavior of
MoreExecutors.newSequentialExecutor(java.util.concurrent.Executor). If your tasks all run on the same underlying executor and don't need to wait forFutures returned fromAsyncCallables, use it instead.- Since:
- 26.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classExecutionSequencer.RunningState
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<ListenableFuture<java.lang.Object>>refThis reference acts as a pointer tracking the head of a linked list of ListenableFutures.
-
Constructor Summary
Constructors Modifier Constructor Description privateExecutionSequencer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ExecutionSequencercreate()Creates a new instance.<T> ListenableFuture<T>submit(java.util.concurrent.Callable<T> callable, java.util.concurrent.Executor executor)Enqueues a task to run when the previous task (if any) completes.<T> ListenableFuture<T>submitAsync(AsyncCallable<T> callable, java.util.concurrent.Executor executor)Enqueues a task to run when the previous task (if any) completes.
-
-
-
Field Detail
-
ref
private final java.util.concurrent.atomic.AtomicReference<ListenableFuture<java.lang.Object>> ref
This reference acts as a pointer tracking the head of a linked list of ListenableFutures.
-
-
Method Detail
-
create
public static ExecutionSequencer create()
Creates a new instance.
-
submit
public <T> ListenableFuture<T> submit(java.util.concurrent.Callable<T> callable, java.util.concurrent.Executor executor)
Enqueues a task to run when the previous task (if any) completes.Cancellation does not propagate from the output future to a callable that has begun to execute, but if the output future is cancelled before
Callable.call()is invoked,Callable.call()will not be invoked.
-
submitAsync
public <T> ListenableFuture<T> submitAsync(AsyncCallable<T> callable, java.util.concurrent.Executor executor)
Enqueues a task to run when the previous task (if any) completes.Cancellation does not propagate from the output future to the future returned from
callableor a callable that has begun to execute, but if the output future is cancelled beforeAsyncCallable.call()is invoked,AsyncCallable.call()will not be invoked.
-
-