Class SubmitterSchedulerQueueLimitRejector
- java.lang.Object
-
- org.threadly.concurrent.AbstractSubmitterExecutor
-
- org.threadly.concurrent.AbstractSubmitterScheduler
-
- org.threadly.concurrent.wrapper.limiter.SubmitterSchedulerQueueLimitRejector
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,SubmitterExecutor
,SubmitterScheduler
- Direct Known Subclasses:
SchedulerServiceQueueLimitRejector
public class SubmitterSchedulerQueueLimitRejector extends AbstractSubmitterScheduler
A simple way to limit anySubmitterScheduler
so that queues are managed. In addition this queue is tracked completely independent of theSubmitterScheduler
's actual queue, so these can be distributed in code to limit queues differently to different parts of the system, while letting them all back the sameSubmitterScheduler
.Once the limit has been reached, if additional tasks are supplied the rejected execution handler will be invoked with the rejected tasks (which by default will throw a
RejectedExecutionException
). This is the threadly equivalent of supplying a limited sized blocking queue to a java.util.concurrent thread pool. SeeExecutorQueueLimitRejector
,SchedulerServiceQueueLimitRejector
andPrioritySchedulerServiceQueueLimitRejector
as other possible implementations.- Since:
- 4.6.0 (since 4.3.0 at org.threadly.concurrent.limiter)
-
-
Constructor Summary
Constructors Constructor Description SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler, int queuedTaskLimit)
Constructs a newSubmitterSchedulerQueueLimitRejector
with the provided scheduler and limit.SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
Constructs a newSubmitterSchedulerQueueLimitRejector
with the provided scheduler and limit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getQueuedTaskCount()
Invoked to check how many tasks are currently being tracked as queued by this limiter.int
getQueueLimit()
Invoked to check the currently set queue limit.void
scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period)
Schedule a fixed rate recurring task to run.void
scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay)
Schedule a fixed delay recurring task to run.void
setQueueLimit(int newLimit)
Invoked to change the set limit.-
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.SubmitterExecutor
submit, submit, submit
-
Methods inherited from interface org.threadly.concurrent.SubmitterScheduler
submitScheduled
-
-
-
-
Constructor Detail
-
SubmitterSchedulerQueueLimitRejector
public SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler, int queuedTaskLimit)
Constructs a newSubmitterSchedulerQueueLimitRejector
with the provided scheduler and limit.- Parameters:
parentScheduler
- Scheduler to execute and schedule tasks on toqueuedTaskLimit
- Maximum number of queued tasks before executions should be rejected
-
SubmitterSchedulerQueueLimitRejector
public SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
Constructs a newSubmitterSchedulerQueueLimitRejector
with the provided scheduler and limit.- Parameters:
parentScheduler
- Scheduler to execute and schedule tasks on toqueuedTaskLimit
- Maximum number of queued tasks before executions should be rejectedrejectedExecutionHandler
- Handler to accept tasks which could not be executed due to queue size- Since:
- 4.8.0
-
-
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 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 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 executedinitialDelay
- delay in milliseconds until first runperiod
- amount of time in milliseconds between the start of recurring executions
-
getQueuedTaskCount
public int getQueuedTaskCount()
Invoked to check how many tasks are currently being tracked as queued by this limiter.- Returns:
- Number of tracked tasks waiting for execution to start
-
getQueueLimit
public int getQueueLimit()
Invoked to check the currently set queue limit.- Returns:
- Maximum number of tasks allowed to queue in the parent executor
-
setQueueLimit
public void setQueueLimit(int newLimit)
Invoked to change the set limit. Negative and zero limits are allowed, but they will cause all executions to be rejected. If set below the current queue size, those tasks will still remain queued for execution.- Parameters:
newLimit
- New limit to avoid executions
-
-