Class ScheduledExecutorScheduler

  • All Implemented Interfaces:
    Dumpable, LifeCycle, Scheduler

    @ManagedObject
    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​(@Name("name")
                                          java.lang.String name,
                                          @Name("daemon")
                                          boolean daemon,
                                          @Name("threads")
                                          int threads)
      • ScheduledExecutorScheduler

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

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

        public ScheduledExecutorScheduler​(@Name("name")
                                          java.lang.String name,
                                          @Name("daemon")
                                          boolean daemon,
                                          @Name("classLoader")
                                          java.lang.ClassLoader classLoader,
                                          @Name("threadGroup")
                                          java.lang.ThreadGroup threadGroup,
                                          @Name("threads")
                                          int threads)
        Parameters:
        name - The name of the scheduler threads or null for automatic name
        daemon - True if scheduler threads should be daemon
        classLoader - The classloader to run the threads with or null to use the current thread context classloader
        threadGroup - The threadgroup to use or null for no thread group
        threads - The number of threads to pass to the the core ScheduledThreadPoolExecutor or -1 for a heuristic determined number of threads.
    • 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
      • getName

        @ManagedAttribute("The name of the scheduler")
        public java.lang.String getName()
      • isDaemon

        @ManagedAttribute("Whether the scheduler uses daemon threads")
        public boolean isDaemon()
      • getThreads

        @ManagedAttribute("The number of scheduler threads")
        public int getThreads()