|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.netarkivet.common.lifecycle.PeriodicTaskExecutor
public class PeriodicTaskExecutor
This class wraps a ScheduledThreadPoolExecutor
, allowing to
periodically run one or several Runnable
tasks
(fixed rate execution).
It actively monitors task execution in a separate "checker" thread, allowing
to catch and process any RuntimeException
that would be thrown during
task execution, which cannot be done by simply overriding
ThreadPoolExecutor.afterExecute(java.lang.Runnable, java.lang.Throwable)
.
TODO: Currently RuntimeException
are only caught and logged, but the
executor stops scheduling future executions. We should implement a
configurable restart mechanism, possibly with exception filtering.
Nested Class Summary | |
---|---|
static class |
PeriodicTaskExecutor.PeriodicTask
Represents a periodic task |
Field Summary | |
---|---|
(package private) static org.apache.commons.logging.Log |
log
The class logger. |
Constructor Summary | |
---|---|
PeriodicTaskExecutor(PeriodicTaskExecutor.PeriodicTask... tasks)
Builds an executor for a set of tasks. |
|
PeriodicTaskExecutor(java.lang.String taskId,
java.lang.Runnable task,
long secondsBeforeFirstExec,
long secondsBetweenExec)
Builds an executor for a single task. |
Method Summary | |
---|---|
void |
shutdown()
Shuts down the executor, attempting to stop any ongoing task execution. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final org.apache.commons.logging.Log log
Constructor Detail |
---|
public PeriodicTaskExecutor(java.lang.String taskId, java.lang.Runnable task, long secondsBeforeFirstExec, long secondsBetweenExec)
taskId
- the task id string (should be unique)task
- the actual Runnable
object.secondsBeforeFirstExec
- the delay in seconds between starting
the executor and the initial task execution.secondsBetweenExec
- the delay in seconds between two successive
task executions.public PeriodicTaskExecutor(PeriodicTaskExecutor.PeriodicTask... tasks)
tasks
- the task definitions.Method Detail |
---|
public void shutdown()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |