Class ScheduledExecutorScheduler

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.thread.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 Details

    • ScheduledExecutorScheduler

      public ScheduledExecutorScheduler()
    • ScheduledExecutorScheduler

      public ScheduledExecutorScheduler(String name, boolean daemon)
    • ScheduledExecutorScheduler

      public ScheduledExecutorScheduler(@Name("name") String name, @Name("daemon") boolean daemon, @Name("threads") int threads)
    • ScheduledExecutorScheduler

      public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader classLoader)
    • ScheduledExecutorScheduler

      public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader classLoader, ThreadGroup threadGroup)
    • ScheduledExecutorScheduler

      public ScheduledExecutorScheduler(@Name("name") String name, @Name("daemon") boolean daemon, @Name("classLoader") ClassLoader classLoader, @Name("threadGroup") 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 core ScheduledExecutorService or -1 for a heuristic determined number of threads.
    • ScheduledExecutorScheduler

      public ScheduledExecutorScheduler(ScheduledExecutorService scheduledExecutorService)
      Parameters:
      scheduledExecutorService - the core ScheduledExecutorService to be used
  • Method Details

    • doStart

      protected void doStart() throws Exception
      Description copied from class: AbstractLifeCycle
      Method to override to start the lifecycle
      Overrides:
      doStart in class AbstractLifeCycle
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • doStop

      protected void doStop() throws Exception
      Description copied from class: AbstractLifeCycle
      Method to override to stop the lifecycle
      Overrides:
      doStop in class AbstractLifeCycle
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • schedule

      public Scheduler.Task schedule(Runnable task, long delay, TimeUnit unit)
      Description copied from interface: Scheduler

      Schedules a task to be executed after the given delay.

      Specified by:
      schedule in interface Scheduler
      Parameters:
      task - the task to execute
      delay - the delay value
      unit - the unit of time of the delay
      Returns:
      a delayed task
    • dump

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

      public void dump(Appendable out, String indent) throws 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:
      IOException - if unable to write to Appendable
    • getName

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

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

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