Class SchedulerServiceTaskInterceptor
- java.lang.Object
-
- org.threadly.concurrent.wrapper.interceptor.ExecutorTaskInterceptor
-
- org.threadly.concurrent.wrapper.interceptor.SubmitterSchedulerTaskInterceptor
-
- org.threadly.concurrent.wrapper.interceptor.SchedulerServiceTaskInterceptor
-
- All Implemented Interfaces:
java.util.concurrent.Executor
,SchedulerService
,SubmitterExecutor
,SubmitterScheduler
- Direct Known Subclasses:
PrioritySchedulerTaskInterceptor
public class SchedulerServiceTaskInterceptor extends SubmitterSchedulerTaskInterceptor implements SchedulerService
Class to wrapSchedulerService
pool so that tasks can be intercepted and either wrapped, or modified, before being submitted to the pool. This class can be passed a lambda toSchedulerServiceTaskInterceptor(SchedulerService, BiFunction)
}, orSubmitterSchedulerTaskInterceptor.wrapTask(Runnable, boolean)
can be overridden to provide the task which should be submitted to theSchedulerService
. Please see the javadocs ofSubmitterSchedulerTaskInterceptor.wrapTask(Runnable, boolean)
for more details about ways a task can be modified or wrapped.Other variants of task wrappers:
ExecutorTaskInterceptor
,SubmitterSchedulerTaskInterceptor
,PrioritySchedulerTaskInterceptor
.- Since:
- 4.6.0
-
-
Constructor Summary
Constructors Constructor Description SchedulerServiceTaskInterceptor(SchedulerService parentScheduler, java.util.function.BiFunction<java.lang.Runnable,java.lang.Boolean,java.lang.Runnable> taskManipulator)
Constructs a wrapper forSchedulerService
pool so that tasks can be intercepted and modified, before being submitted to the pool.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getActiveTaskCount()
Call to check how many tasks are currently being executed in this scheduler.int
getQueuedTaskCount()
Returns how many tasks are either waiting to be executed, or are scheduled to be executed at a future point.int
getWaitingForExecutionTaskCount()
Returns how many tasks are either waiting to be executed.boolean
isShutdown()
Function to check if the thread pool is currently accepting and handling tasks.boolean
remove(java.lang.Runnable task)
Removes the runnable task from the execution queue.boolean
remove(java.util.concurrent.Callable<?> task)
Removes the callable task from the execution queue.-
Methods inherited from class org.threadly.concurrent.wrapper.interceptor.SubmitterSchedulerTaskInterceptor
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, wrapTask, wrapTask
-
Methods inherited from class org.threadly.concurrent.wrapper.interceptor.ExecutorTaskInterceptor
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, submit, submit
-
Methods inherited from interface org.threadly.concurrent.SubmitterScheduler
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduled
-
-
-
-
Constructor Detail
-
SchedulerServiceTaskInterceptor
public SchedulerServiceTaskInterceptor(SchedulerService parentScheduler, java.util.function.BiFunction<java.lang.Runnable,java.lang.Boolean,java.lang.Runnable> taskManipulator)
Constructs a wrapper forSchedulerService
pool so that tasks can be intercepted and modified, before being submitted to the pool.- Parameters:
parentScheduler
- An instance ofSchedulerService
to wraptaskManipulator
- A lambda to manipulate aRunnable
that was submitted for execution
-
-
Method Detail
-
remove
public boolean remove(java.lang.Runnable task)
Description copied from interface:SchedulerService
Removes the runnable task from the execution queue. It is possible for the runnable to still run until this call has returned.Note 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.- Specified by:
remove
in interfaceSchedulerService
- Parameters:
task
- The original runnable provided to the executor- Returns:
true
if the runnable was found and removed
-
remove
public boolean remove(java.util.concurrent.Callable<?> task)
Description copied from interface:SchedulerService
Removes the callable task from the execution queue. It is possible for the callable to still run until this call has returned.Note 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.- Specified by:
remove
in interfaceSchedulerService
- Parameters:
task
- The original callable provided to the executor- Returns:
true
if the callable was found and removed
-
getActiveTaskCount
public int getActiveTaskCount()
Description copied from interface:SchedulerService
Call to check how many tasks are currently being executed in this scheduler.- Specified by:
getActiveTaskCount
in interfaceSchedulerService
- Returns:
- current number of running tasks
-
getQueuedTaskCount
public int getQueuedTaskCount()
Description copied from interface:SchedulerService
Returns how many tasks are either waiting to be executed, or are scheduled to be executed at a future point. This can indicate pool back pressure, but it can also just indicate generally scheduled tasks. It's computationally cheaper thanSchedulerService.getWaitingForExecutionTaskCount()
.- Specified by:
getQueuedTaskCount
in interfaceSchedulerService
- Returns:
- quantity of tasks waiting execution or scheduled to be executed later
-
getWaitingForExecutionTaskCount
public int getWaitingForExecutionTaskCount()
Description copied from interface:SchedulerService
Returns how many tasks are either waiting to be executed. A value here can indicate the pool is being starved for threads.- Specified by:
getWaitingForExecutionTaskCount
in interfaceSchedulerService
- Returns:
- quantity of tasks waiting execution
-
isShutdown
public boolean isShutdown()
Description copied from interface:SchedulerService
Function to check if the thread pool is currently accepting and handling tasks.- Specified by:
isShutdown
in interfaceSchedulerService
- Returns:
true
if thread pool is running
-
-