|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.tangosol.util.Base
com.tangosol.util.Daemon
com.tangosol.util.TaskDaemon
public class TaskDaemon
A Daemon thread handler that asynchronously executes Runnable tasks, either at a scheduled time or "as soon as possible".
Nested Class Summary | |
---|---|
class |
TaskDaemon.PeriodicTask
A PeriodicTask is a task that automatically reschedules itself so that it executes on a periodic basis. |
Nested classes/interfaces inherited from class com.tangosol.util.Daemon |
---|
Daemon.DaemonWorker |
Constructor Summary | |
---|---|
TaskDaemon()
Default constructor. |
|
TaskDaemon(String sName)
Creates a TaskDaemon with the specified name. |
|
TaskDaemon(String sName,
int nPriority,
boolean fStart)
Creates a TaskDaemon with a specified name and priority. |
|
TaskDaemon(String sName,
int nPriority,
boolean fStart,
boolean fFinish,
int cMillisTimeout)
Creates a TaskDaemon with a specified name and priority. |
Method Summary | |
---|---|
void |
executePeriodicTask(Runnable task,
long cMillisInterval)
Schedule a periodic task to be run "as soon as possible", and to repeat at the specified interval. |
void |
executeTask(Runnable task)
Schedule a task to be run by the daemon "as soon as possible". |
protected String |
getDescription()
Format the Daemon attributes into a String for inclusion in the String returned from the Daemon.toString() method. |
long |
getIdleTimeout()
Determine the length of time that the daemon will live without any activity before it stops itself. |
protected long |
getMostRecentTaskTime()
Determine when the most recent task was run. |
protected LongArray |
getTasks()
Obtain the pending tasks. |
protected Runnable |
instantiatePeriodicTask(Runnable task,
long cMillisInterval)
Create a task that will automatically be run on a periodic basis. |
boolean |
isFinishing()
Determine if the daemon will finish those scheduled tasks that are ripe (presently due to be run) before stopping. |
protected void |
onException(Throwable e,
Runnable task)
Process an exception that is thrown during a task execution. |
void |
run()
The task processing loop. |
protected void |
run(Runnable task)
Execute a Runnable task. |
void |
schedulePeriodicTask(Runnable task,
long ldtFirst,
long cMillisInterval)
Schedule a periodic task to be run at the specified time, and to repeat at the specified interval. |
void |
scheduleTask(Runnable task,
long ldt)
Schedule a task to be run at the specified time, or as soon after as possible. |
void |
setFinishing(boolean fFinish)
Specify whether the daemon will finish scheduled tasks before stopping. |
void |
setIdleTimeout(long cMillis)
Configure the daemon's timeout. |
void |
stop(boolean fFinish)
Request the daemon to stop, optionally completing tasks that have already been scheduled and are ready to be run. |
protected Runnable |
takeNextRipeTask()
Wait for the next scheduled task is ripe (due or overdue), then remove it from the pending schedule and return it. |
String |
toString()
Return a human-readable String representation of the Daemon. |
protected void |
updateMostRecentTaskTime()
Set the time that the most recent task was run to the current time. |
Methods inherited from class com.tangosol.util.Daemon |
---|
changeState, configureWorker, getConfiguredName, getConfiguredPriority, getState, getThread, getThreadContextClassLoader, getWorker, instantiateWorker, isOnWorkerThread, isRunning, isStopping, setConfiguredName, setConfiguredPriority, setThreadContextClassLoader, start, stop, toStateString |
Constructor Detail |
---|
public TaskDaemon()
public TaskDaemon(String sName)
sName
- the thread name (may be null)public TaskDaemon(String sName, int nPriority, boolean fStart)
sName
- the thread name (may be null)nPriority
- the thread priority, between Thread.MIN_PRIORITY and
Thread.MAX_PRIORITY inclusivefStart
- pass true to start the thread immediatelypublic TaskDaemon(String sName, int nPriority, boolean fStart, boolean fFinish, int cMillisTimeout)
sName
- the thread name (may be null)nPriority
- the thread priority, between Thread.MIN_PRIORITY and
Thread.MAX_PRIORITY inclusivefStart
- pass true to start the thread immediatelyfFinish
- pass true to makes sure ripe tasks are run before the
daemon shuts downcMillisTimeout
- the number of milliseconds to wait after the
previous task finsished for a new task to be
submitted before automatically shutting down the
daemon threadMethod Detail |
---|
public void run()
run
in interface Runnable
run
in class Daemon
public void stop(boolean fFinish)
fFinish
- pass true if the daemon should finish any tasks that
have already been scheduled before stoppingpublic boolean isFinishing()
public void setFinishing(boolean fFinish)
fFinish
- pass true to force the daemon to finish any scheduled
tasks before stoppingpublic long getIdleTimeout()
public void setIdleTimeout(long cMillis)
cMillis
- if greater than zero, the number of milliseconds that
the daemon will wait with nothing in the queue before
shutting itself downpublic void executeTask(Runnable task)
task
- a Runnable object to invokepublic void scheduleTask(Runnable task, long ldt)
task
- a Runnable object to invokeldt
- a datetime value at which to run the taskpublic void executePeriodicTask(Runnable task, long cMillisInterval)
task
- a Runnable object to invokecMillisInterval
- the number of milliseconds to wait after the
task is run before running it againpublic void schedulePeriodicTask(Runnable task, long ldtFirst, long cMillisInterval)
task
- a Runnable object to invokeldtFirst
- a datetime value at which to first run the taskcMillisInterval
- the number of milliseconds to wait after the
task is run before running it againprotected LongArray getTasks()
protected Runnable takeNextRipeTask() throws InterruptedException
InterruptedException
protected void run(Runnable task)
task
- a Runnable objectprotected long getMostRecentTaskTime()
protected void updateMostRecentTaskTime()
protected Runnable instantiatePeriodicTask(Runnable task, long cMillisInterval)
task
- the actual task to runcMillisInterval
- the period of time, in milliseconds, to
wait between runs of the task
public String toString()
toString
in class Daemon
protected String getDescription()
Daemon.toString()
method.
getDescription
in class Daemon
protected void onException(Throwable e, Runnable task)
e
- Throwable object (a RuntimeException or an Error)task
- the task that caused the exception
|
CoherenceTM v3.3 Copyright© 2000-2007 by Oracle Corporation |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |