Class SingleThreadSchedulerSubPool

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

    public class SingleThreadSchedulerSubPool
    extends AbstractPriorityScheduler
    This sub-pool is a special type of limiter. It is able to have expanded semantics than the pool it delegates to. For example this pool provides TaskPriority capabilities even though the pool it runs on top of does not necessarily provide that. In addition most status's returned do not consider the parent pools state (for example getActiveTaskCount() does not reflect the active tasks in the parent pool).

    Most importantly difference in this "sub-pool" vs "limiter" is the way task execution order is maintained in the delegate pool. In a limiter tasks will need to queue individually against the other tasks the delegate pool needs to execute. In this implementation the sub-pool basically gets CPU time and it will attempt to execute everything it needs to. It will not return the thread to the delegate pool until there is nothing left to process.

    There are two big reasons you might want to use this sub pool over a limiter. As long as the above details are not problematic, this is a much more efficient implementation. Providing better load characteristics for submitting tasks, as well reducing the burden on the delegate pool. In addition if you need limiter + priority capabilities, this is your only option.

    Since:
    5.7
    • Constructor Detail

      • SingleThreadSchedulerSubPool

        public SingleThreadSchedulerSubPool​(SchedulerService delegateScheduler)
        Construct a new single threaded sub-pool.
        Parameters:
        delegateScheduler - Scheduler to gain CPU time for task execution
      • SingleThreadSchedulerSubPool

        public SingleThreadSchedulerSubPool​(SchedulerService delegateScheduler,
                                            TaskPriority defaultPriority,
                                            long maxWaitForLowPriorityInMs)
        Construct a new single threaded sub-pool with default task priority behaviors.
        Parameters:
        delegateScheduler - Scheduler to gain CPU time for task execution
        defaultPriority - Default priority for tasks submitted to this pool
        maxWaitForLowPriorityInMs - time low priority tasks to wait if there are high priority tasks ready to run
    • Method Detail

      • scheduleWithFixedDelay

        public void scheduleWithFixedDelay​(java.lang.Runnable task,
                                           long initialDelay,
                                           long recurringDelay,
                                           TaskPriority priority)
        Description copied from interface: PrioritySchedulerService
        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
        priority - priority for task to get available thread to run on
      • scheduleAtFixedRate

        public void scheduleAtFixedRate​(java.lang.Runnable task,
                                        long initialDelay,
                                        long period,
                                        TaskPriority priority)
        Description copied from interface: PrioritySchedulerService
        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
        priority - priority for task to get available thread to run on
      • getActiveTaskCount

        public int getActiveTaskCount()
        Description copied from interface: SchedulerService
        Call to check how many tasks are currently being executed in this scheduler.
        Returns:
        current number of running tasks
      • isShutdown

        public boolean isShutdown()
        Description copied from interface: SchedulerService
        Function to check if the thread pool is currently accepting and handling tasks.
        Returns:
        true if thread pool is running