public class SchedulerServiceTaskInterceptor extends SubmitterSchedulerTaskInterceptor implements SchedulerService
SchedulerService
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 to
SchedulerServiceTaskInterceptor(SchedulerService, BiFunction)
}, or
SubmitterSchedulerTaskInterceptor.wrapTask(Runnable, boolean)
can be overridden to provide the task which should be
submitted to the SchedulerService
. Please see the javadocs of
SubmitterSchedulerTaskInterceptor.wrapTask(Runnable, boolean)
for more details about ways a task can be modified or
wrapped.
Other variants of task wrappers: ExecutorTaskInterceptor
,
SubmitterSchedulerTaskInterceptor
, PrioritySchedulerTaskInterceptor
.
Constructor and Description |
---|
SchedulerServiceTaskInterceptor(SchedulerService parentScheduler,
java.util.function.BiFunction<java.lang.Runnable,java.lang.Boolean,java.lang.Runnable> taskManipulator)
Constructs a wrapper for
SchedulerService pool so that tasks can be intercepted and modified,
before being submitted to the pool. |
Modifier and Type | Method and 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.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.
|
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, wrapTask, wrapTask
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
schedule, scheduleAtFixedRate, scheduleWithFixedDelay, submitScheduled, submitScheduled, submitScheduled
submit, submit, submit
public SchedulerServiceTaskInterceptor(SchedulerService parentScheduler, java.util.function.BiFunction<java.lang.Runnable,java.lang.Boolean,java.lang.Runnable> taskManipulator)
SchedulerService
pool so that tasks can be intercepted and modified,
before being submitted to the pool.parentScheduler
- An instance of SchedulerService
to wraptaskManipulator
- A lambda to manipulate a Runnable
that was submitted for executionpublic boolean remove(java.lang.Runnable task)
SchedulerService
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.
remove
in interface SchedulerService
task
- The original runnable provided to the executortrue
if the runnable was found and removedpublic boolean remove(java.util.concurrent.Callable<?> task)
SchedulerService
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.
remove
in interface SchedulerService
task
- The original callable provided to the executortrue
if the callable was found and removedpublic int getActiveTaskCount()
SchedulerService
getActiveTaskCount
in interface SchedulerService
public int getQueuedTaskCount()
SchedulerService
SchedulerService.getWaitingForExecutionTaskCount()
.getQueuedTaskCount
in interface SchedulerService
public int getWaitingForExecutionTaskCount()
SchedulerService
getWaitingForExecutionTaskCount
in interface SchedulerService
public boolean isShutdown()
SchedulerService
isShutdown
in interface SchedulerService
true
if thread pool is running