dk.netarkivet.common.lifecycle
Class PeriodicTaskExecutor

java.lang.Object
  extended by dk.netarkivet.common.lifecycle.PeriodicTaskExecutor

public class PeriodicTaskExecutor
extends java.lang.Object

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

log

static final org.apache.commons.logging.Log log
The class logger.

Constructor Detail

PeriodicTaskExecutor

public PeriodicTaskExecutor(java.lang.String taskId,
                            java.lang.Runnable task,
                            long secondsBeforeFirstExec,
                            long secondsBetweenExec)
Builds an executor for a single task.

Parameters:
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.

PeriodicTaskExecutor

public PeriodicTaskExecutor(PeriodicTaskExecutor.PeriodicTask... tasks)
Builds an executor for a set of tasks.

Parameters:
tasks - the task definitions.
Method Detail

shutdown

public void shutdown()
Shuts down the executor, attempting to stop any ongoing task execution.