com.shimari.framework
Class Cron

java.lang.Object
  extended bycom.shimari.framework.Cron
All Implemented Interfaces:
Component, java.lang.Runnable

public class Cron
extends java.lang.Object
implements java.lang.Runnable, Component

Execute periodic events. We have a pool of worker thread which execute tasks on a periodic schedule. The tasks themselves are responsible for scheduling decisions. The model followed is to wait until the next task's execution time, _remove_ that task from the queue and execute it. Once the task has completed we put it back into the queue, querying it to see how long until its next run (if the answer is '0' we drop the task). The minimum wait time is 100 milliseconds (1/10th of a second).

We remove the task from the queue when we execute it for a few reasons: one, so that the same task won't be executed by concurrent threads if it takes longer than its interval time to execute; two, so that if it hangs it just blocks one thread and since it's not back on the queue won't block anyone else. We will hang completely only if N different tasks all hang, where N is the number of threads we have available.


Constructor Summary
Cron(Config config)
           
 
Method Summary
 void addTask(CronTask task)
          Add a new task to the queue.
 void init(Registry registry)
           
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cron

public Cron(Config config)
     throws ConfigException
Method Detail

init

public void init(Registry registry)
Specified by:
init in interface Component
See Also:
Component.init(com.shimari.framework.Registry)

addTask

public void addTask(CronTask task)
Add a new task to the queue.


run

public void run()
Specified by:
run in interface java.lang.Runnable