public class BasicScheduledTaskService extends WWObjectImpl implements ScheduledTaskService, java.lang.Thread.UncaughtExceptionHandler
Modifier and Type | Class and Description |
---|---|
protected class |
BasicScheduledTaskService.ScheduledTaskExecutor
Custom executor to run tasks.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.ConcurrentLinkedQueue<java.lang.Runnable> |
activeTasks
Tasks currently running.
|
protected static int |
DEFAULT_POOL_SIZE
Default thread pool size.
|
protected BasicScheduledTaskService.ScheduledTaskExecutor |
executor
Executor for running tasks.
|
protected static java.lang.String |
IDLE_THREAD_NAME_PREFIX
Name assigned to idle threads.
|
protected static java.lang.String |
RUNNING_THREAD_NAME_PREFIX
Name assigned to active threads.
|
Constructor and Description |
---|
BasicScheduledTaskService()
Create a new scheduled task service.
|
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.ScheduledFuture<?> |
addRepeatingTask(java.lang.Runnable runnable,
long initialDelay,
long period,
java.util.concurrent.TimeUnit timeunit)
Enqueues a task to run periodically.
|
java.util.concurrent.ScheduledFuture<?> |
addScheduledTask(java.lang.Runnable runnable,
long delay,
java.util.concurrent.TimeUnit timeunit)
Enqueues a task to run after a delay.
|
void |
addTask(java.lang.Runnable runnable)
Enqueues a task to run.
|
void |
shutdown(boolean immediately)
Shut down the service.
|
void |
uncaughtException(java.lang.Thread thread,
java.lang.Throwable throwable) |
onMessage, propertyChange
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
protected java.util.concurrent.ConcurrentLinkedQueue<java.lang.Runnable> activeTasks
protected static final int DEFAULT_POOL_SIZE
protected BasicScheduledTaskService.ScheduledTaskExecutor executor
protected static final java.lang.String IDLE_THREAD_NAME_PREFIX
protected static final java.lang.String RUNNING_THREAD_NAME_PREFIX
public BasicScheduledTaskService()
AVKey.TASK_POOL_SIZE
.public java.util.concurrent.ScheduledFuture<?> addRepeatingTask(java.lang.Runnable runnable, long initialDelay, long period, java.util.concurrent.TimeUnit timeunit)
ScheduledExecutorService.scheduleAtFixedRate(java.lang.Runnable, long, long, java.util.concurrent.TimeUnit)
. Duplicate tasks are ignored.addRepeatingTask
in interface ScheduledTaskService
runnable
- the task to add.initialDelay
- delay before the first execution of the task. timeUnit
determines the units of the
value.period
- interval between executions of the task. timeUnit
determines the units of the value.timeunit
- time unit of initialDelay
and period
.null
if
the task was not enqueued.public java.util.concurrent.ScheduledFuture<?> addScheduledTask(java.lang.Runnable runnable, long delay, java.util.concurrent.TimeUnit timeunit)
addScheduledTask
in interface ScheduledTaskService
runnable
- the task to add.delay
- delay before execution of the task. timeUnit
determines the units of the value.timeunit
- time unit of initialDelay
and period
.null
if
the task was not enqueued.public void addTask(java.lang.Runnable runnable)
addTask
in interface ScheduledTaskService
runnable
- the task to addpublic void shutdown(boolean immediately)
ScheduledTaskService
immediate
parameter is true
, the service will attempt to stop all
active tasks, and will not begin work on any other tasks in the queue. Otherwise, the service will complete all
tasks in the work queue, but will not accept any new tasks.shutdown
in interface ScheduledTaskService
immediately
- true
to shutdown immediately.public void uncaughtException(java.lang.Thread thread, java.lang.Throwable throwable)
uncaughtException
in interface java.lang.Thread.UncaughtExceptionHandler