public class SubmitterSchedulerQueueLimitRejector extends AbstractSubmitterScheduler
SubmitterScheduler
so that queues are managed. In addition
this queue is tracked completely independent of the SubmitterScheduler
'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 same SubmitterScheduler
.
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.
See ExecutorQueueLimitRejector
, SchedulerServiceQueueLimitRejector
and
PrioritySchedulerServiceQueueLimitRejector
as other possible implementations.
Constructor and Description |
---|
SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler,
int queuedTaskLimit)
Constructs a new
SubmitterSchedulerQueueLimitRejector with the provided scheduler and limit. |
SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler,
int queuedTaskLimit,
RejectedExecutionHandler rejectedExecutionHandler)
Constructs a new
SubmitterSchedulerQueueLimitRejector with the provided scheduler and limit. |
Modifier and Type | Method and 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.
|
schedule, submitScheduled, submitScheduled
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
submitScheduled
submit, submit, submit
public SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler, int queuedTaskLimit)
SubmitterSchedulerQueueLimitRejector
with the provided scheduler and limit.parentScheduler
- Scheduler to execute and schedule tasks on toqueuedTaskLimit
- Maximum number of queued tasks before executions should be rejectedpublic SubmitterSchedulerQueueLimitRejector(SubmitterScheduler parentScheduler, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
SubmitterSchedulerQueueLimitRejector
with the provided scheduler and limit.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 sizepublic void scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay)
SubmitterScheduler
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 finishpublic void scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period)
SubmitterScheduler
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 executionspublic int getQueuedTaskCount()
public int getQueueLimit()
public void setQueueLimit(int newLimit)
newLimit
- New limit to avoid executions