Class SerializingExecutor

java.lang.Object
io.grpc.internal.SerializingExecutor
All Implemented Interfaces:
Runnable, Executor

public final class SerializingExecutor extends Object implements Executor, Runnable
Executor ensuring that all Runnable tasks submitted are executed in order using the provided Executor, and serially such that no two will ever be running at the same time.
  • Field Details

    • log

      private static final Logger log
    • atomicHelper

      private static final SerializingExecutor.AtomicHelper atomicHelper
    • STOPPED

      private static final int STOPPED
      See Also:
    • RUNNING

      private static final int RUNNING
      See Also:
    • executor

      private Executor executor
      Underlying executor that all submitted Runnable objects are run on.
    • runQueue

      private final Queue<Runnable> runQueue
      A list of Runnables to be run in order.
    • runState

      private volatile int runState
  • Constructor Details

    • SerializingExecutor

      public SerializingExecutor(Executor executor)
      Creates a SerializingExecutor, running tasks using executor.
      Parameters:
      executor - Executor in which tasks should be run. Must not be null.
  • Method Details

    • getAtomicHelper

      private static SerializingExecutor.AtomicHelper getAtomicHelper()
    • setExecutor

      public void setExecutor(Executor executor)
      Only call this from this SerializingExecutor Runnable, so that the executor is immediately visible to this SerializingExecutor executor.
    • execute

      public void execute(Runnable r)
      Runs the given runnable strictly after all Runnables that were submitted before it, and using the executor passed to the constructor. .
      Specified by:
      execute in interface Executor
    • schedule

      private void schedule(@Nullable Runnable removable)
    • run

      public void run()
      Specified by:
      run in interface Runnable