public class ExecutorQueueLimitRejector extends AbstractSubmitterExecutor
Executor
so that queues are managed. In addition this queue
is tracked completely independent of the Executor
'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 Executor
.
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
and PrioritySchedulerServiceQueueLimitRejector
as other possible implementations.
Constructor and Description |
---|
ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor,
int queuedTaskLimit)
Constructs a new
ExecutorQueueLimitRejector with the provided scheduler and limit. |
ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor,
int queuedTaskLimit,
RejectedExecutionHandler rejectedExecutionHandler)
Constructs a new
ExecutorQueueLimitRejector 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 |
setQueueLimit(int newLimit)
Invoked to change the set limit.
|
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
submit
public ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor, int queuedTaskLimit)
ExecutorQueueLimitRejector
with the provided scheduler and limit.parentExecutor
- Executor to execute tasks on toqueuedTaskLimit
- Maximum number of queued tasks before executions should be rejectedpublic ExecutorQueueLimitRejector(java.util.concurrent.Executor parentExecutor, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
ExecutorQueueLimitRejector
with the provided scheduler and limit.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 sizepublic int getQueuedTaskCount()
public int getQueueLimit()
public void setQueueLimit(int newLimit)
newLimit
- New limit to avoid executions