Class GenericScheduledExecutorService

  • All Implemented Interfaces:
    SchedulerLifecycle

    public final class GenericScheduledExecutorService
    extends java.lang.Object
    implements SchedulerLifecycle
    A default ScheduledExecutorService that can be used for scheduling actions when a Scheduler implementation doesn't have that ability.

    For example if a Scheduler is given an Executor or {ExecutorService instead of ScheduledExecutorService.

    NOTE: No actual work should be done on tasks submitted to this executor. Submit a task with the appropriate delay which then in turn invokes the work asynchronously on the appropriate Scheduler implementation. This means for example that you would not use this approach along with TrampolineScheduler or ImmediateScheduler.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledExecutorService[]> executor  
      static GenericScheduledExecutorService INSTANCE  
      private static java.util.concurrent.ScheduledExecutorService[] NONE  
      private static int roundRobin
      We don't use atomics with this because thread-assignment is random anyway.
      private static java.util.concurrent.ScheduledExecutorService SHUTDOWN  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.concurrent.ScheduledExecutorService getInstance()
      Returns one of the single-threaded ScheduledExecutorService helper executors.
      void shutdown()
      Instructs the Scheduler instance to stop threads and stop accepting tasks on any outstanding Workers.
      void start()
      Allows the Scheduler instance to start threads and accept tasks on them.
      • Methods inherited from class java.lang.Object

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

      • NONE

        private static final java.util.concurrent.ScheduledExecutorService[] NONE
      • SHUTDOWN

        private static final java.util.concurrent.ScheduledExecutorService SHUTDOWN
      • executor

        private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledExecutorService[]> executor
      • roundRobin

        private static int roundRobin
        We don't use atomics with this because thread-assignment is random anyway.
    • Constructor Detail

      • GenericScheduledExecutorService

        private GenericScheduledExecutorService()
    • Method Detail

      • start

        public void start()
        Description copied from interface: SchedulerLifecycle
        Allows the Scheduler instance to start threads and accept tasks on them.

        Implementations should make sure the call is idempotent and threadsafe.

        Specified by:
        start in interface SchedulerLifecycle
      • shutdown

        public void shutdown()
        Description copied from interface: SchedulerLifecycle
        Instructs the Scheduler instance to stop threads and stop accepting tasks on any outstanding Workers.

        Implementations should make sure the call is idempotent and threadsafe.

        Specified by:
        shutdown in interface SchedulerLifecycle
      • getInstance

        public static java.util.concurrent.ScheduledExecutorService getInstance()
        Returns one of the single-threaded ScheduledExecutorService helper executors.
        Returns:
        ScheduledExecutorService for generic use.