Class SchedulerServiceQueueLimitRejector
- java.lang.Object
-
- org.threadly.concurrent.AbstractSubmitterExecutor
-
- org.threadly.concurrent.AbstractSubmitterScheduler
-
- org.threadly.concurrent.wrapper.limiter.SubmitterSchedulerQueueLimitRejector
-
- org.threadly.concurrent.wrapper.limiter.SchedulerServiceQueueLimitRejector
-
- All Implemented Interfaces:
java.util.concurrent.Executor,SchedulerService,SubmitterExecutor,SubmitterScheduler
- Direct Known Subclasses:
PrioritySchedulerServiceQueueLimitRejector
public class SchedulerServiceQueueLimitRejector extends SubmitterSchedulerQueueLimitRejector implements SchedulerService
A simple way to limit anySchedulerServiceso that queues are managed. In addition this queue is tracked completely independent of theSchedulerService'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 sameSchedulerService.Once the limit has been reached, if additional tasks are supplied a
RejectedExecutionExceptionwill be thrown. This is the threadly equivalent of supplying a limited sized blocking queue to a java.util.concurrent thread pool.See
ExecutorQueueLimitRejector,SubmitterSchedulerQueueLimitRejectorandPrioritySchedulerServiceQueueLimitRejectoras other possible implementations.- Since:
- 4.6.0 (since 4.3.0 at org.threadly.concurrent.limiter)
-
-
Constructor Summary
Constructors Constructor Description SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler, int queuedTaskLimit)Constructs a newSchedulerServiceQueueLimitRejectorwith the provided scheduler and limit.SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)Constructs a newSchedulerServiceQueueLimitRejectorwith the provided scheduler and limit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetActiveTaskCount()Call to check how many tasks are currently being executed in this scheduler.intgetWaitingForExecutionTaskCount()Returns how many tasks are either waiting to be executed.booleanisShutdown()Function to check if the thread pool is currently accepting and handling tasks.booleanremove(java.lang.Runnable task)Removes the runnable task from the execution queue.booleanremove(java.util.concurrent.Callable<?> task)Removes the callable task from the execution queue.-
Methods inherited from class org.threadly.concurrent.wrapper.limiter.SubmitterSchedulerQueueLimitRejector
getQueuedTaskCount, getQueueLimit, scheduleAtFixedRate, scheduleWithFixedDelay, setQueueLimit
-
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.SchedulerService
getQueuedTaskCount
-
Methods inherited from interface org.threadly.concurrent.SubmitterExecutor
submit, submit, submit
-
Methods inherited from interface org.threadly.concurrent.SubmitterScheduler
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduled
-
-
-
-
Constructor Detail
-
SchedulerServiceQueueLimitRejector
public SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler, int queuedTaskLimit)
Constructs a newSchedulerServiceQueueLimitRejectorwith 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
-
SchedulerServiceQueueLimitRejector
public SchedulerServiceQueueLimitRejector(SchedulerService parentScheduler, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
Constructs a newSchedulerServiceQueueLimitRejectorwith 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
-
getWaitingForExecutionTaskCount
public int getWaitingForExecutionTaskCount()
Description copied from interface:SchedulerServiceReturns how many tasks are either waiting to be executed. A value here can indicate the pool is being starved for threads.- Specified by:
getWaitingForExecutionTaskCountin interfaceSchedulerService- Returns:
- quantity of tasks waiting execution
-
remove
public boolean remove(java.lang.Runnable task)
Description copied from interface:SchedulerServiceRemoves the runnable task from the execution queue. It is possible for the runnable to still run until this call has returned.Note 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.- Specified by:
removein interfaceSchedulerService- Parameters:
task- The original runnable provided to the executor- Returns:
trueif the runnable was found and removed
-
remove
public boolean remove(java.util.concurrent.Callable<?> task)
Description copied from interface:SchedulerServiceRemoves the callable task from the execution queue. It is possible for the callable to still run until this call has returned.Note 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.- Specified by:
removein interfaceSchedulerService- Parameters:
task- The original callable provided to the executor- Returns:
trueif the callable was found and removed
-
getActiveTaskCount
public int getActiveTaskCount()
Description copied from interface:SchedulerServiceCall to check how many tasks are currently being executed in this scheduler.- Specified by:
getActiveTaskCountin interfaceSchedulerService- Returns:
- current number of running tasks
-
isShutdown
public boolean isShutdown()
Description copied from interface:SchedulerServiceFunction to check if the thread pool is currently accepting and handling tasks.- Specified by:
isShutdownin interfaceSchedulerService- Returns:
trueif thread pool is running
-
-