Class SerializingExecutor

  • All Implemented Interfaces:
    java.lang.Runnable, java.util.concurrent.Executor

    public final class SerializingExecutor
    extends java.lang.Object
    implements java.util.concurrent.Executor, java.lang.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 Detail

      • log

        private static final java.util.logging.Logger log
      • executor

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

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

        private volatile int runState
    • Constructor Detail

      • SerializingExecutor

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

      • setExecutor

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

        public void execute​(java.lang.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 java.util.concurrent.Executor
      • schedule

        private void schedule​(@Nullable
                              java.lang.Runnable removable)
      • run

        public void run()
        Specified by:
        run in interface java.lang.Runnable