Class 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 any Futures 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 for Futures returned from AsyncCallables, use it instead.

    Since:
    26.0
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ExecutionSequencer create()
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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 callable or a callable that has begun to execute, but if the output future is cancelled before AsyncCallable.call() is invoked, AsyncCallable.call() will not be invoked.