public class DefaultPriorityWrapper extends java.lang.Object implements PrioritySchedulerService
PrioritySchedulerService. The purpose of wrapping
like this would be to change the default priority from the wrapped instance. That way this
could be passed into other parts of code and although use the same thread pool, have different
default priorities. (this could be particularly useful when used in combination with
KeyDistributedExecutor, or
KeyDistributedScheduler.| Constructor and Description |
|---|
DefaultPriorityWrapper(PrioritySchedulerService scheduler,
TaskPriority defaultPriority)
Constructs a new priority wrapper with a new default priority to use.
|
| Modifier and Type | Method and Description |
|---|---|
static PrioritySchedulerService |
ensurePriority(PrioritySchedulerService scheduler,
TaskPriority defaultPriority)
Convenience function for wrapping the scheduler if the default priority is not what is desired.
|
void |
execute(java.lang.Runnable command) |
void |
execute(java.lang.Runnable task,
TaskPriority priority)
Executes the task as soon as possible for the given priority.
|
int |
getActiveTaskCount()
Call to check how many tasks are currently being executed in this scheduler.
|
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()
Returns how many tasks are either waiting to be executed, or are scheduled to be executed at
a future point.
|
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()
Returns how many tasks are either waiting to be executed.
|
int |
getWaitingForExecutionTaskCount(TaskPriority priority)
Returns a count of how many tasks are either waiting to be executed for a specific priority.
|
boolean |
isShutdown()
Function to check if the thread pool is currently accepting and handling tasks.
|
boolean |
remove(java.util.concurrent.Callable<?> task)
Removes the callable task from the execution queue.
|
boolean |
remove(java.lang.Runnable task)
Removes the runnable task from the execution queue.
|
void |
schedule(java.lang.Runnable task,
long delayInMs)
Schedule a one time task with a given delay.
|
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)
Schedule a fixed rate recurring task to run.
|
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)
Schedule a fixed delay 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)
Submit a
Callable to run as soon as possible. |
<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)
Submit a task to run as soon as possible.
|
<T> ListenableFuture<T> |
submit(java.lang.Runnable task,
T result)
Submit a task to run as soon as possible.
|
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)
Schedule a
Callable with a given delay. |
<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)
Schedule a task 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)
Schedule a task with a given delay.
|
<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.
|
public DefaultPriorityWrapper(PrioritySchedulerService scheduler, TaskPriority defaultPriority)
scheduler - PriorityScheduler implementation to default todefaultPriority - default priority for tasks submitted without a prioritypublic static PrioritySchedulerService ensurePriority(PrioritySchedulerService scheduler, TaskPriority defaultPriority)
scheduler - Scheduler to check priority against or wrapdefaultPriority - The default priority the returned scheduler should havepublic void execute(java.lang.Runnable command)
execute in interface java.util.concurrent.Executorpublic void execute(java.lang.Runnable task,
TaskPriority priority)
PrioritySchedulerServiceexecute in interface PrioritySchedulerServicetask - runnable to executepriority - priority for task to get available thread to run onpublic ListenableFuture<?> submit(java.lang.Runnable task)
SubmitterExecutorSubmitterExecutor.submit(Runnable) over Executor.execute(Runnable). So this should only be used when
the returned future is necessary.
The Future.get() method will return null once the runnable has
completed.
submit in interface SubmitterExecutortask - runnable to be executedpublic <T> ListenableFuture<T> submit(java.lang.Runnable task, T result)
SubmitterExecutorFuture.get() method will
return the provided result once the runnable has completed.submit in interface SubmitterExecutorT - type of result for futuretask - runnable to be executedresult - result to be returned from resulting future .get() when runnable completespublic ListenableFuture<?> submit(java.lang.Runnable task, TaskPriority priority)
PrioritySchedulerService
The Future.get() method will return null once the runnable has
completed.
submit in interface PrioritySchedulerServicetask - 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 PrioritySchedulerServiceT - 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)
SubmitterExecutorCallable to run as soon as possible. This is needed when a result needs to
be consumed from the callable.submit in interface SubmitterExecutorT - type of result returned from the futuretask - callable to be executedpublic <T> ListenableFuture<T> submit(java.util.concurrent.Callable<T> task, TaskPriority priority)
PrioritySchedulerServiceCallable 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 PrioritySchedulerServiceT - 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)
SubmitterSchedulerschedule in interface SubmitterSchedulertask - runnable to executedelayInMs - time in milliseconds to wait to execute taskpublic void schedule(java.lang.Runnable task,
long delayInMs,
TaskPriority priority)
PrioritySchedulerServiceschedule in interface PrioritySchedulerServicetask - 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)
SubmitterSchedulerSubmitterScheduler.submitScheduled(Runnable, long) over SubmitterScheduler.schedule(Runnable, long). 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 SubmitterSchedulertask - runnable to executedelayInMs - time in milliseconds to wait to execute taskpublic <T> ListenableFuture<T> submitScheduled(java.lang.Runnable task, T result, long delayInMs)
SubmitterSchedulerFuture.get() method will return
the provided result once the runnable has completed.submitScheduled in interface SubmitterSchedulerT - 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 taskpublic ListenableFuture<?> submitScheduled(java.lang.Runnable task, long delayInMs, TaskPriority priority)
PrioritySchedulerServicePrioritySchedulerService.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 PrioritySchedulerServicetask - 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 PrioritySchedulerServiceT - 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)
SubmitterSchedulerCallable with a given delay. This is needed when a result needs to be
consumed from the callable.submitScheduled in interface SubmitterSchedulerT - type of result returned from the futuretask - callable to be executeddelayInMs - time in milliseconds to wait to execute taskpublic <T> ListenableFuture<T> submitScheduled(java.util.concurrent.Callable<T> task, long delayInMs, TaskPriority priority)
PrioritySchedulerServiceCallable with a given delay. This is needed when a result needs to be
consumed from the callable.submitScheduled in interface PrioritySchedulerServiceT - 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)
SubmitterSchedulerrecurringDelay + 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 SubmitterSchedulertask - runnable to be executedinitialDelay - delay in milliseconds until first runrecurringDelay - delay in milliseconds for running task after last finishpublic void scheduleWithFixedDelay(java.lang.Runnable task,
long initialDelay,
long recurringDelay,
TaskPriority priority)
PrioritySchedulerServicerecurringDelay + 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 PrioritySchedulerServicetask - 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)
SubmitterScheduler
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 SubmitterSchedulertask - runnable to be executedinitialDelay - delay in milliseconds until first runperiod - amount of time in milliseconds between the start of recurring executionspublic 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 PrioritySchedulerServicetask - 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 boolean remove(java.lang.Runnable task)
SchedulerServiceNote 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.
remove in interface SchedulerServicetask - The original runnable provided to the executortrue if the runnable was found and removedpublic boolean remove(java.util.concurrent.Callable<?> task)
SchedulerServiceNote 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.
remove in interface SchedulerServicetask - The original callable provided to the executortrue if the callable was found and removedpublic boolean isShutdown()
SchedulerServiceisShutdown in interface SchedulerServicetrue if thread pool is runningpublic TaskPriority getDefaultPriority()
PrioritySchedulerServicegetDefaultPriority in interface PrioritySchedulerServicepublic long getMaxWaitForLowPriority()
PrioritySchedulerServicegetMaxWaitForLowPriority in interface PrioritySchedulerServicepublic int getActiveTaskCount()
SchedulerServicegetActiveTaskCount in interface SchedulerServicepublic int getQueuedTaskCount()
SchedulerServiceSchedulerService.getWaitingForExecutionTaskCount().getQueuedTaskCount in interface SchedulerServicepublic int getQueuedTaskCount(TaskPriority priority)
PrioritySchedulerServicePrioritySchedulerService.getWaitingForExecutionTaskCount(TaskPriority).getQueuedTaskCount in interface PrioritySchedulerServicepriority - priority for tasks to be countedpublic int getWaitingForExecutionTaskCount()
SchedulerServicegetWaitingForExecutionTaskCount in interface SchedulerServicepublic int getWaitingForExecutionTaskCount(TaskPriority priority)
PrioritySchedulerServicegetWaitingForExecutionTaskCount in interface PrioritySchedulerServicepriority - priority for tasks to be counted