Class ExecutorQueueLimitRejector
- java.lang.Object
-
- org.threadly.concurrent.AbstractSubmitterExecutor
-
- org.threadly.concurrent.wrapper.limiter.ExecutorQueueLimitRejector
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,SubmitterExecutor
public class ExecutorQueueLimitRejector extends AbstractSubmitterExecutor
A simple way to limit anyExecutor
so that queues are managed. In addition this queue is tracked completely independent of theExecutor
'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 sameExecutor
.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
SubmitterSchedulerQueueLimitRejector
,SchedulerServiceQueueLimitRejector
andPrioritySchedulerServiceQueueLimitRejector
as other possible implementations.- Since:
- 4.6.0 (since 4.3.0 at org.threadly.concurrent.limiter)
-
-
Constructor Summary
Constructors Constructor Description ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor, int queuedTaskLimit)
Constructs a newExecutorQueueLimitRejector
with the provided scheduler and limit.ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
Constructs a newExecutorQueueLimitRejector
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
setQueueLimit(int newLimit)
Invoked to change the set limit.-
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
-
-
-
-
Constructor Detail
-
ExecutorQueueLimitRejector
public ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor, int queuedTaskLimit)
Constructs a newExecutorQueueLimitRejector
with the provided scheduler and limit.- Parameters:
parentExecutor
- Executor to execute tasks on toqueuedTaskLimit
- Maximum number of queued tasks before executions should be rejected
-
ExecutorQueueLimitRejector
public ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
Constructs a newExecutorQueueLimitRejector
with the provided scheduler and limit.- Parameters:
parentExecutor
- Executor to execute 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
-
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
-
-