Interface PrioritySchedulerService
-
- All Superinterfaces:
java.util.concurrent.Executor
,SchedulerService
,SubmitterExecutor
,SubmitterScheduler
- All Known Subinterfaces:
StatisticPriorityScheduler
- All Known Implementing Classes:
AbstractPriorityScheduler
,DefaultPriorityWrapper
,NoThreadScheduler
,NoThreadSchedulerStatisticTracker
,PriorityDelegatingScheduler
,PriorityScheduler
,PrioritySchedulerServiceQueueLimitRejector
,PrioritySchedulerStatisticTracker
,PrioritySchedulerTaskInterceptor
,SingleThreadScheduler
,SingleThreadSchedulerStatisticTracker
,SingleThreadSchedulerSubPool
,ThreadRenamingPriorityScheduler
public interface PrioritySchedulerService extends SchedulerService
This interface represents schedulers which can not only execute and schedule tasks, but run based off a given priority as well.- Since:
- 4.3.0 (since 1.0.0 as PrioritySchedulerInterface)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method 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.default 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>
submit(java.util.concurrent.Callable<T> task, TaskPriority priority)
Submit aCallable
to run as soon as possible for the given priority.default 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.<T> ListenableFuture<T>
submitScheduled(java.util.concurrent.Callable<T> task, long delayInMs, TaskPriority priority)
Schedule aCallable
with a given delay.-
Methods inherited from interface org.threadly.concurrent.SchedulerService
getActiveTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, isShutdown, remove, remove
-
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
-
-
-
-
Method Detail
-
execute
void execute(java.lang.Runnable task, TaskPriority priority)
Executes the task as soon as possible for the given priority.- Parameters:
task
- runnable to executepriority
- priority for task to get available thread to run on
-
submit
default ListenableFuture<?> submit(java.lang.Runnable task, TaskPriority priority)
Submit a task to run as soon as possible for the given priority. There is a slight increase in load when using submit over execute. So this should only be used when the future is necessary.The
Future.get()
method will returnnull
once the runnable has completed.- Parameters:
task
- runnable to be executedpriority
- priority for task to get available thread to run on- Returns:
- a future to know when the task has completed
-
submit
<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. There is a slight increase in load when using submit over execute. So this should only be used when the future is necessary.The
Future.get()
method will return the provided result once the runnable has completed.- Type Parameters:
T
- type of result returned from the future- Parameters:
task
- runnable to be executedresult
- result to be returned from resulting future .get() when runnable completespriority
- priority for task to get available thread to run on- Returns:
- a future to know when the task has completed
-
submit
<T> ListenableFuture<T> submit(java.util.concurrent.Callable<T> task, TaskPriority priority)
Submit aCallable
to run as soon as possible for the given priority. This is needed when a result needs to be consumed from the callable.- Type Parameters:
T
- type of result returned from the future- Parameters:
task
- callable to be executedpriority
- priority for task to get available thread to run on- Returns:
- a future to know when the task has completed and get the result of the callable
-
schedule
void schedule(java.lang.Runnable task, long delayInMs, TaskPriority priority)
Schedule a task with a given delay and a specified priority.- Parameters:
task
- runnable to executedelayInMs
- time in milliseconds to wait to execute taskpriority
- priority for task to get available thread to run on
-
submitScheduled
default ListenableFuture<?> submitScheduled(java.lang.Runnable task, long delayInMs, TaskPriority priority)
Schedule a task with a given delay and a specified priority. There is a slight increase in load when usingsubmitScheduled(Runnable, long, TaskPriority)
overschedule(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.- Parameters:
task
- runnable to executedelayInMs
- time in milliseconds to wait to execute taskpriority
- priority for task to get available thread to run on- Returns:
- a future to know when the task has completed
-
submitScheduled
<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.The
Future.get()
method will return the provided result once the runnable has completed.- Type Parameters:
T
- type of result returned from the future- Parameters:
task
- 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 on- Returns:
- a future to know when the task has completed
-
submitScheduled
<T> ListenableFuture<T> submitScheduled(java.util.concurrent.Callable<T> task, long delayInMs, TaskPriority priority)
Schedule aCallable
with a given delay. This is needed when a result needs to be consumed from the callable.- Type Parameters:
T
- type of result returned from the future- Parameters:
task
- callable to be executeddelayInMs
- time in milliseconds to wait to execute taskpriority
- priority for task to get available thread to run on- Returns:
- a future to know when the task has completed and get the result of the callable
-
scheduleWithFixedDelay
void scheduleWithFixedDelay(java.lang.Runnable task, long initialDelay, long recurringDelay, TaskPriority priority)
Schedule a fixed delay recurring task to run. The recurring delay time will be from the point where execution has finished. So the execution frequency is therecurringDelay + 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).- Parameters:
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 on
-
scheduleAtFixedRate
void scheduleAtFixedRate(java.lang.Runnable task, long initialDelay, long period, TaskPriority priority)
Schedule a fixed rate recurring task to run. The recurring delay will be the same, regardless of how long task execution takes. A given runnable will not run concurrently (unless it is submitted to the scheduler multiple times). Instead of execution takes longer than the period, the next run will occur immediately (given thread availability in the pool).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).- Parameters:
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 on
-
getDefaultPriority
TaskPriority getDefaultPriority()
Get the default priority for the scheduler.- Returns:
- the set default task priority
-
getMaxWaitForLowPriority
long getMaxWaitForLowPriority()
Getter for the amount of time a low priority task will wait during thread contention before it is eligible for execution.- Returns:
- currently set max wait for low priority task
-
getQueuedTaskCount
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. This can indicate pool back pressure, but it can also just indicate generally scheduled tasks. It's computationally cheaper thangetWaitingForExecutionTaskCount(TaskPriority)
.- Parameters:
priority
- priority for tasks to be counted- Returns:
- quantity of tasks waiting execution or scheduled to be executed later
-
getWaitingForExecutionTaskCount
int getWaitingForExecutionTaskCount(TaskPriority priority)
Returns a count of how many tasks are either waiting to be executed for a specific priority. A value here can indicate the pool is being starved for threads.- Parameters:
priority
- priority for tasks to be counted- Returns:
- quantity of tasks waiting execution
-
-