public class PrioritySchedulerServiceQueueLimitRejector extends SchedulerServiceQueueLimitRejector implements PrioritySchedulerService
PrioritySchedulerService
so that queues are managed. In
addition this queue is tracked completely independent of the PrioritySchedulerService
'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 PrioritySchedulerService
.
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
SchedulerServiceQueueLimitRejector
as other possible implementations.
Constructor and Description |
---|
PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler,
int queuedTaskLimit)
Constructs a new
PrioritySchedulerServiceQueueLimitRejector with the provided
scheduler and limit. |
PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler,
int queuedTaskLimit,
boolean dontLimitStarvable)
Constructs a new
PrioritySchedulerServiceQueueLimitRejector with the provided
scheduler and limit. |
PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler,
int queuedTaskLimit,
boolean dontLimitStarvable,
RejectedExecutionHandler rejectedExecutionHandler)
Constructs a new
PrioritySchedulerServiceQueueLimitRejector with the provided
scheduler, limit, and handler for when task can not be submitted to the pool. |
PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler,
int queuedTaskLimit,
RejectedExecutionHandler rejectedExecutionHandler)
Constructs a new
PrioritySchedulerServiceQueueLimitRejector with the provided
scheduler, limit, and handler for when task can not be submitted to the pool. |
Modifier and Type | Method and Description |
---|---|
void |
execute(java.lang.Runnable task,
TaskPriority priority)
Executes the task as soon as possible for the given priority.
|
TaskPriority |
getDefaultPriority()
Get the default priority for the scheduler.
|
long |
getMaxWaitForLowPriority()
Getter for the amount of time a low priority task will wait during thread contention before
it is eligible for execution.
|
int |
getQueuedTaskCount(TaskPriority priority)
Returns a count of how many tasks are either waiting to be executed, or are scheduled to be
executed at a future point for a specific priority.
|
int |
getWaitingForExecutionTaskCount(TaskPriority priority)
Returns a count of how many tasks are either waiting to be executed for a specific priority.
|
void |
schedule(java.lang.Runnable task,
long delayInMs,
TaskPriority priority)
Schedule a task with a given delay and a specified priority.
|
void |
scheduleAtFixedRate(java.lang.Runnable task,
long initialDelay,
long period,
TaskPriority priority)
Schedule a fixed rate recurring task to run.
|
void |
scheduleWithFixedDelay(java.lang.Runnable task,
long initialDelay,
long recurringDelay,
TaskPriority priority)
Schedule a fixed delay recurring task to run.
|
<T> ListenableFuture<T> |
submit(java.util.concurrent.Callable<T> task,
TaskPriority priority)
Submit a
Callable to run as soon as possible for the given priority. |
ListenableFuture<?> |
submit(java.lang.Runnable task,
TaskPriority priority)
Submit a task to run as soon as possible for the given priority.
|
<T> ListenableFuture<T> |
submit(java.lang.Runnable task,
T result,
TaskPriority priority)
Submit a task to run as soon as possible for the given priority.
|
<T> ListenableFuture<T> |
submitScheduled(java.util.concurrent.Callable<T> task,
long delayInMs,
TaskPriority priority)
Schedule a
Callable with a given delay. |
ListenableFuture<?> |
submitScheduled(java.lang.Runnable task,
long delayInMs,
TaskPriority priority)
Schedule a task with a given delay and a specified priority.
|
<T> ListenableFuture<T> |
submitScheduled(java.lang.Runnable task,
T result,
long delayInMs,
TaskPriority priority)
Schedule a task with a given delay and a specified priority.
|
getActiveTaskCount, getWaitingForExecutionTaskCount, isShutdown, remove, remove
getQueuedTaskCount, getQueueLimit, scheduleAtFixedRate, scheduleWithFixedDelay, setQueueLimit
schedule, submitScheduled, submitScheduled
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getActiveTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, isShutdown, remove, remove
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduled
submit, submit, submit
public PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler, int queuedTaskLimit)
PrioritySchedulerServiceQueueLimitRejector
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 PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler, int queuedTaskLimit, RejectedExecutionHandler rejectedExecutionHandler)
PrioritySchedulerServiceQueueLimitRejector
with the provided
scheduler, limit, and handler for when task can not be submitted to the pool.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 PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler, int queuedTaskLimit, boolean dontLimitStarvable)
PrioritySchedulerServiceQueueLimitRejector
with the provided
scheduler and limit. This constructor additionally allows you to specify if starvable tasks
should be included in the queue limit. Because starvable tasks have less impact on the pool,
the need to limit them may be reduced.parentScheduler
- Scheduler to execute and schedule tasks on toqueuedTaskLimit
- Maximum number of queued tasks before executions should be rejecteddontLimitStarvable
- Provide true
to don't include starvable tasks against queue limitpublic PrioritySchedulerServiceQueueLimitRejector(PrioritySchedulerService parentScheduler, int queuedTaskLimit, boolean dontLimitStarvable, RejectedExecutionHandler rejectedExecutionHandler)
PrioritySchedulerServiceQueueLimitRejector
with the provided
scheduler, limit, and handler for when task can not be submitted to the pool. This
constructor additionally allows you to specify if starvable tasks should be included in the
queue limit. Because starvable tasks have less impact on the pool, the need to limit them
may be reduced.parentScheduler
- Scheduler to execute and schedule tasks on toqueuedTaskLimit
- Maximum number of queued tasks before executions should be rejecteddontLimitStarvable
- Provide true
to don't include starvable tasks against queue limitrejectedExecutionHandler
- Handler to accept tasks which could not be executed due to queue sizepublic void execute(java.lang.Runnable task, TaskPriority priority)
PrioritySchedulerService
execute
in interface PrioritySchedulerService
task
- runnable to executepriority
- priority for task to get available thread to run onpublic ListenableFuture<?> submit(java.lang.Runnable task, TaskPriority priority)
PrioritySchedulerService
The Future.get()
method will return null
once the runnable has
completed.
submit
in interface PrioritySchedulerService
task
- runnable to be executedpriority
- priority for task to get available thread to run onpublic <T> ListenableFuture<T> submit(java.lang.Runnable task, T result, TaskPriority priority)
PrioritySchedulerService
The Future.get()
method will return the provided result once the runnable has
completed.
submit
in interface PrioritySchedulerService
T
- type of result returned from the futuretask
- runnable to be executedresult
- result to be returned from resulting future .get() when runnable completespriority
- priority for task to get available thread to run onpublic <T> ListenableFuture<T> submit(java.util.concurrent.Callable<T> task, TaskPriority priority)
PrioritySchedulerService
Callable
to run as soon as possible for the given priority. This is needed
when a result needs to be consumed from the callable.submit
in interface PrioritySchedulerService
T
- type of result returned from the futuretask
- callable to be executedpriority
- priority for task to get available thread to run onpublic void schedule(java.lang.Runnable task, long delayInMs, TaskPriority priority)
PrioritySchedulerService
schedule
in interface PrioritySchedulerService
task
- runnable to executedelayInMs
- time in milliseconds to wait to execute taskpriority
- priority for task to get available thread to run onpublic ListenableFuture<?> submitScheduled(java.lang.Runnable task, long delayInMs, TaskPriority priority)
PrioritySchedulerService
PrioritySchedulerService.submitScheduled(Runnable, long, TaskPriority)
over
PrioritySchedulerService.schedule(Runnable, long, TaskPriority)
. So this should only be used when the
future is necessary.
The Future.get()
method will return null once the runnable has completed.
submitScheduled
in interface PrioritySchedulerService
task
- runnable to executedelayInMs
- time in milliseconds to wait to execute taskpriority
- priority for task to get available thread to run onpublic <T> ListenableFuture<T> submitScheduled(java.lang.Runnable task, T result, long delayInMs, TaskPriority priority)
PrioritySchedulerService
The Future.get()
method will return the provided result once the runnable
has completed.
submitScheduled
in interface PrioritySchedulerService
T
- type of result returned from the futuretask
- runnable to executeresult
- result to be returned from resulting future .get() when runnable completesdelayInMs
- time in milliseconds to wait to execute taskpriority
- priority for task to get available thread to run onpublic <T> ListenableFuture<T> submitScheduled(java.util.concurrent.Callable<T> task, long delayInMs, TaskPriority priority)
PrioritySchedulerService
Callable
with a given delay. This is needed when a result needs to be
consumed from the callable.submitScheduled
in interface PrioritySchedulerService
T
- type of result returned from the futuretask
- callable to be executeddelayInMs
- time in milliseconds to wait to execute taskpriority
- priority for task to get available thread to run onpublic void scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay, TaskPriority priority)
PrioritySchedulerService
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).
scheduleWithFixedDelay
in interface PrioritySchedulerService
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runrecurringDelay
- delay in milliseconds for running task after last finishpriority
- priority for task to get available thread to run onpublic void scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, TaskPriority priority)
PrioritySchedulerService
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).
scheduleAtFixedRate
in interface PrioritySchedulerService
task
- runnable to be executedinitialDelay
- delay in milliseconds until first runperiod
- amount of time in milliseconds between the start of recurring executionspriority
- priority for task to get available thread to run onpublic TaskPriority getDefaultPriority()
PrioritySchedulerService
getDefaultPriority
in interface PrioritySchedulerService
public long getMaxWaitForLowPriority()
PrioritySchedulerService
getMaxWaitForLowPriority
in interface PrioritySchedulerService
public int getQueuedTaskCount(TaskPriority priority)
PrioritySchedulerService
PrioritySchedulerService.getWaitingForExecutionTaskCount(TaskPriority)
.getQueuedTaskCount
in interface PrioritySchedulerService
priority
- priority for tasks to be countedpublic int getWaitingForExecutionTaskCount(TaskPriority priority)
PrioritySchedulerService
getWaitingForExecutionTaskCount
in interface PrioritySchedulerService
priority
- priority for tasks to be counted