Class ScheduledExecutorScheduler

  • All Implemented Interfaces:
    Dumpable, LifeCycle, Scheduler

    public class ScheduledExecutorScheduler
    extends AbstractLifeCycle
    implements Scheduler, Dumpable
    Implementation of Scheduler based on JDK's ScheduledThreadPoolExecutor.

    While use of ScheduledThreadPoolExecutor creates futures that will not be used, it has the advantage of allowing to set a property to remove cancelled tasks from its queue even if the task did not fire, which provides a huge benefit in the performance of garbage collection in young generation.

    • Constructor Detail

      • ScheduledExecutorScheduler

        public ScheduledExecutorScheduler()
      • ScheduledExecutorScheduler

        public ScheduledExecutorScheduler​(java.lang.String name,
                                          boolean daemon)
      • ScheduledExecutorScheduler

        public ScheduledExecutorScheduler​(java.lang.String name,
                                          boolean daemon,
                                          java.lang.ClassLoader threadFactoryClassLoader)
      • ScheduledExecutorScheduler

        public ScheduledExecutorScheduler​(java.lang.String name,
                                          boolean daemon,
                                          java.lang.ClassLoader threadFactoryClassLoader,
                                          java.lang.ThreadGroup threadGroup)
    • Method Detail

      • doStart

        protected void doStart()
                        throws java.lang.Exception
        Overrides:
        doStart in class AbstractLifeCycle
        Throws:
        java.lang.Exception
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Overrides:
        doStop in class AbstractLifeCycle
        Throws:
        java.lang.Exception
      • schedule

        public Scheduler.Task schedule​(java.lang.Runnable task,
                                       long delay,
                                       java.util.concurrent.TimeUnit unit)
        Specified by:
        schedule in interface Scheduler
      • dump

        public java.lang.String dump()
        Specified by:
        dump in interface Dumpable
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable