Class SingleThreadSchedulerSubPool
- java.lang.Object
-
- org.threadly.concurrent.AbstractSubmitterExecutor
-
- org.threadly.concurrent.AbstractSubmitterScheduler
-
- org.threadly.concurrent.AbstractPriorityScheduler
-
- org.threadly.concurrent.wrapper.limiter.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 providesTaskPriority
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 examplegetActiveTaskCount()
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 Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.threadly.concurrent.AbstractPriorityScheduler
execute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, getWaitingForExecutionTaskCount, remove, remove, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setMaxWaitForLowPriority, submit, submit, submitScheduled, submitScheduled
-
Methods inherited from class org.threadly.concurrent.AbstractSubmitterScheduler
schedule, submitScheduled, submitScheduled
-
Methods inherited from class org.threadly.concurrent.AbstractSubmitterExecutor
execute, submit, submit
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.threadly.concurrent.PrioritySchedulerService
submit, submitScheduled
-
Methods inherited from interface org.threadly.concurrent.SubmitterExecutor
submit, submit, submit
-
Methods inherited from interface org.threadly.concurrent.SubmitterScheduler
schedule, submitScheduled, submitScheduled, submitScheduled
-
-
-
-
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 executiondefaultPriority
- Default priority for tasks submitted to this poolmaxWaitForLowPriorityInMs
- 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 therecurringDelay + 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 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 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 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 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
-
-