public class SingleThreadScheduler extends AbstractPriorityScheduler
SchedulerService
. This is designed to
be a lighter weight option to the PriorityScheduler
, for when multiple threads are
either not needed, or not desired.Constructor and Description |
---|
SingleThreadScheduler()
Constructs a new
SingleThreadScheduler . |
SingleThreadScheduler(boolean daemonThread)
Constructs a new
SingleThreadScheduler . |
SingleThreadScheduler(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs)
Constructs a new
SingleThreadScheduler . |
SingleThreadScheduler(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
boolean daemonThread)
Constructs a new
SingleThreadScheduler . |
SingleThreadScheduler(TaskPriority defaultPriority,
long maxWaitForLowPriorityInMs,
java.util.concurrent.ThreadFactory threadFactory)
Constructs a new
SingleThreadScheduler . |
SingleThreadScheduler(java.util.concurrent.ThreadFactory threadFactory)
Constructs a new
SingleThreadScheduler . |
Modifier and Type | Method and Description |
---|---|
void |
awaitTermination()
Block until the thread pool has shutdown and all threads have been stopped.
|
boolean |
awaitTermination(long timeoutMillis)
Block until the thread pool has shutdown and all threads have been stopped.
|
int |
getActiveTaskCount()
Call to check how many tasks are currently being executed in this scheduler.
|
boolean |
isShutdown()
Function to check if the thread pool is currently accepting and handling tasks.
|
boolean |
isTerminated()
One step beyond
isShutdown() , a true here indicates that not only has a
shutdown on the pool been requested, but that the thread running tasks has completed. |
void |
prestartExecutionThread()
Start thread for execution if not already started.
|
void |
prestartExecutionThread(boolean blockTillStarted)
Start thread for execution if not already started.
|
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.
|
void |
shutdown()
Stops any new tasks from being submitted to the pool.
|
java.util.List<java.lang.Runnable> |
shutdownNow()
Stops any new tasks from being submitted to the pool.
|
execute, getDefaultPriority, getMaxWaitForLowPriority, getQueuedTaskCount, getQueuedTaskCount, getWaitingForExecutionTaskCount, getWaitingForExecutionTaskCount, remove, remove, schedule, scheduleAtFixedRate, scheduleWithFixedDelay, setMaxWaitForLowPriority, submit, submit, submitScheduled, submitScheduled
schedule, submitScheduled, submitScheduled
execute, submit, submit
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
submit, submitScheduled
schedule, submitScheduled, submitScheduled, submitScheduled
submit, submit, submit
public SingleThreadScheduler()
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the scheduler.public SingleThreadScheduler(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs)
SingleThreadScheduler
. No threads will start until the first task
is provided. This defaults to using a daemon thread for the scheduler.defaultPriority
- Default priority for tasks which are submitted without any specified prioritymaxWaitForLowPriorityInMs
- time low priority tasks to wait if there are high priority tasks ready to runpublic SingleThreadScheduler(boolean daemonThread)
SingleThreadScheduler
. No threads will start until the first task
is provided.daemonThread
- true
if scheduler thread should be a daemon threadpublic SingleThreadScheduler(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, boolean daemonThread)
SingleThreadScheduler
. No threads will start until the first task
is provided.defaultPriority
- Default priority for tasks which are submitted without any specified prioritymaxWaitForLowPriorityInMs
- time low priority tasks to wait if there are high priority tasks ready to rundaemonThread
- true
if scheduler thread should be a daemon threadpublic SingleThreadScheduler(java.util.concurrent.ThreadFactory threadFactory)
SingleThreadScheduler
. No threads will start until the first task
is provided.threadFactory
- factory to make thread for schedulerpublic SingleThreadScheduler(TaskPriority defaultPriority, long maxWaitForLowPriorityInMs, java.util.concurrent.ThreadFactory threadFactory)
SingleThreadScheduler
. No threads will start until the first task
is provided.defaultPriority
- Default priority for tasks which are submitted without any specified prioritymaxWaitForLowPriorityInMs
- time low priority tasks to wait if there are high priority tasks ready to runthreadFactory
- factory to make thread for schedulerpublic void shutdown()
shutdown()
or
shutdownNow()
has already been called, this will have no effect.
If you wish to not want to run any queued tasks you should use shutdownNow()
.
public java.util.List<java.lang.Runnable> shutdownNow()
public void awaitTermination() throws java.lang.InterruptedException
shutdown()
or shutdownNow()
is invoked, then this will block forever.java.lang.InterruptedException
- Thrown if blocking thread is interrupted waiting for shutdownpublic boolean awaitTermination(long timeoutMillis) throws java.lang.InterruptedException
shutdown()
or shutdownNow()
is invoked, then this will block until the
timeout is reached.timeoutMillis
- time to block and wait for thread pool to shutdowntrue
if the pool has shutdown, false if timeout was reachedjava.lang.InterruptedException
- Thrown if blocking thread is interrupted waiting for shutdownpublic boolean isShutdown()
SchedulerService
true
if thread pool is runningpublic boolean isTerminated()
isShutdown()
, a true
here indicates that not only has a
shutdown on the pool been requested, but that the thread running tasks has completed.true
if this scheduler is no longer processing any taskspublic void prestartExecutionThread()
public void prestartExecutionThread(boolean blockTillStarted)
blockTillStarted
- If true
this will not return till the scheduler thread has startedpublic 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).
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).
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 int getActiveTaskCount()
SchedulerService