public class SingleThreadSchedulerSubPool extends AbstractPriorityScheduler
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.
Constructor and Description |
---|
SingleThreadSchedulerSubPool(SchedulerService delegateScheduler)
Construct a new single threaded sub-pool.
|
SingleThreadSchedulerSubPool(SchedulerService delegateScheduler,
TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs)
Construct a new single threaded sub-pool with default task priority behaviors.
|
Modifier and Type | Method and Description |
---|---|
int |
getActiveTaskCount()
Call to check how many tasks are currently being executed in this scheduler.
|
boolean |
isShutdown()
Function to check if the thread pool is currently accepting and handling tasks.
|
void |
scheduleAtFixedRate(java.lang.Runnable task,
long initialDelay,
long period,
TaskPriority priority)
Schedule a fixed rate recurring task to run.
|
void |
scheduleWithFixedDelay(java.lang.Runnable task,
long initialDelay,
long recurringDelay,
TaskPriority priority)
Schedule a fixed delay recurring task to run.
|
execute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, getWaitingForExecutionTaskCount, remove, remove, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setMaxWaitForLowPriority, submit, submit, submitScheduled, submitScheduled
schedule, submitScheduled, submitScheduled
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
submit, submitScheduled
schedule, submitScheduled, submitScheduled, submitScheduled
submit, submit, submit
public SingleThreadSchedulerSubPool(SchedulerService delegateScheduler)
delegateScheduler
- Scheduler to gain CPU time for task executionpublic SingleThreadSchedulerSubPool(SchedulerService delegateScheduler, TaskPriority defaultPriority, long maxWaitForLowPriorityInMs)
delegateScheduler
- Scheduler to gain CPU time for task executiondefaultPriority
- Default priority for tasks submitted to this poolmaxWaitForLowPriorityInMs
- time low priority tasks to wait if there are high priority tasks ready to runpublic void scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay, TaskPriority priority)
PrioritySchedulerService
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).
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runrecurringDelay
- delay in milliseconds for running task after last finishpriority
- priority for task to get available thread to run onpublic void scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, TaskPriority priority)
PrioritySchedulerService
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).
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runperiod
- amount of time in milliseconds between the start of recurring executionspriority
- priority for task to get available thread to run onpublic int getActiveTaskCount()
SchedulerService
public boolean isShutdown()
SchedulerService
true
if thread pool is running