public class SchedulerServiceQueueLimitRejector extends SubmitterSchedulerQueueLimitRejector implements SchedulerService
SchedulerService so that queues are managed. In addition
this queue is tracked completely independent of the SchedulerService'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 SchedulerService.
Once the limit has been reached, if additional tasks are supplied a
RejectedExecutionException will be thrown. This is the threadly
equivalent of supplying a limited sized blocking queue to a java.util.concurrent thread
pool.
See ExecutorQueueLimitRejector, SubmitterSchedulerQueueLimitRejector and
PrioritySchedulerServiceQueueLimitRejector as other possible implementations.
| Constructor and Description |
|---|
SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler,
int queuedTaskLimit)
Constructs a new
SchedulerServiceQueueLimitRejector with the provided scheduler and limit. |
SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler,
int queuedTaskLimit,
RejectedExecutionHandler rejectedExecutionHandler)
Constructs a new
SchedulerServiceQueueLimitRejector with the provided scheduler and limit. |
| Modifier and Type | Method and Description |
|---|---|
int |
getActiveTaskCount()
Call to check how many tasks are currently being executed in this scheduler.
|
int |
getWaitingForExecutionTaskCount()
Returns how many tasks are either waiting to be executed.
|
boolean |
isShutdown()
Function to check if the thread pool is currently accepting and handling tasks.
|
boolean |
remove(java.util.concurrent.Callable<?> task)
Removes the callable task from the execution queue.
|
boolean |
remove(java.lang.Runnable task)
Removes the runnable task from the execution queue.
|
getQueuedTaskCount, getQueueLimit, scheduleAtFixedRate, scheduleWithFixedDelay, setQueueLimitschedule, submitScheduled, submitScheduledexecute, submit, submitequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetQueuedTaskCountschedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduledsubmit, submit, submitpublic SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler, int queuedTaskLimit)
SchedulerServiceQueueLimitRejector 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 SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
SchedulerServiceQueueLimitRejector 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 int getWaitingForExecutionTaskCount()
SchedulerServicegetWaitingForExecutionTaskCount in interface SchedulerServicepublic boolean remove(java.lang.Runnable task)
SchedulerServiceNote that this call has high guarantees on the ability to remove the task (as in a complete guarantee). But while this is being invoked, it will reduce the throughput of execution, so should NOT be used extremely frequently.
For non-recurring tasks using a future and calling
Future.cancel(boolean) can be a better solution.
remove in interface SchedulerServicetask - The original runnable provided to the executortrue if the runnable was found and removedpublic boolean remove(java.util.concurrent.Callable<?> task)
SchedulerServiceNote that this call has high guarantees on the ability to remove the task (as in a complete guarantee). But while this is being invoked, it will reduce the throughput of execution, so should NOT be used extremely frequently.
For non-recurring tasks using a future and calling
Future.cancel(boolean) can be a better solution.
remove in interface SchedulerServicetask - The original callable provided to the executortrue if the callable was found and removedpublic int getActiveTaskCount()
SchedulerServicegetActiveTaskCount in interface SchedulerServicepublic boolean isShutdown()
SchedulerServiceisShutdown in interface SchedulerServicetrue if thread pool is running