Class SchedulerExecutorDelegator

  • All Implemented Interfaces:
    java.util.concurrent.Executor, SubmitterExecutor, SubmitterScheduler

    public class SchedulerExecutorDelegator
    extends AbstractSubmitterScheduler
    Class which takes in both an executor and a scheduler. Delegating executions to the executor when possible, and otherwise submitting to the provided scheduler. This can be used to provide different behavior/implementations between scheduled and executed tasks (for example you could use DefaultPriorityWrapper to have a different default priority for scheduled tasks vs executed).
    Since:
    4.7.0
    • Constructor Detail

      • SchedulerExecutorDelegator

        public SchedulerExecutorDelegator​(java.util.concurrent.Executor parentExecutor,
                                          SubmitterScheduler parentScheduler)
        Constructs a new delegator with the provided pools to defer executions to.
        Parameters:
        parentExecutor - Executor to use when ever possible
        parentScheduler - Scheduler to use when executions need to be delayed
    • Method Detail

      • scheduleWithFixedDelay

        public void scheduleWithFixedDelay​(java.lang.Runnable task,
                                           long initialDelay,
                                           long recurringDelay)
        Description copied from interface: SubmitterScheduler
        Schedule a fixed delay recurring task to run. The recurring delay time will be from the point where execution has finished. So the execution frequency is the recurringDelay + runtime for the provided task.

        Unlike ScheduledExecutorService if the task throws an exception, subsequent executions are NOT suppressed or prevented. So if the task throws an exception on every run, the task will continue to be executed at the provided recurring delay (possibly throwing an exception on each execution).

        Parameters:
        task - runnable to be executed
        initialDelay - delay in milliseconds until first run
        recurringDelay - delay in milliseconds for running task after last finish
      • scheduleAtFixedRate

        public void scheduleAtFixedRate​(java.lang.Runnable task,
                                        long initialDelay,
                                        long period)
        Description copied from interface: SubmitterScheduler
        Schedule a fixed rate recurring task to run. The recurring delay will be the same, regardless of how long task execution takes. A given runnable will not run concurrently (unless it is submitted to the scheduler multiple times). Instead of execution takes longer than the period, the next run will occur immediately (given thread availability in the pool).

        Unlike ScheduledExecutorService if the task throws an exception, subsequent executions are NOT suppressed or prevented. So if the task throws an exception on every run, the task will continue to be executed at the provided recurring delay (possibly throwing an exception on each execution).

        Parameters:
        task - runnable to be executed
        initialDelay - delay in milliseconds until first run
        period - amount of time in milliseconds between the start of recurring executions