thinkmap.server.cron
Class CronTab
java.lang.Object
thinkmap.server.cron.CronTab
- All Implemented Interfaces:
- Runnable
public class CronTab
- extends Object
- implements Runnable
The CronTab is a class that allows you to schedule jobs that get run
at regular intervals. It is similar in functionality to the "cron"
facility in unix.
The CronTab is not exceptionally acurate - it tends to have an accuracy
of about +-10 milliseconds. The CronTab will spawn additional threads to run
jobs if any (or many) jobs are taking too long to process. Worker threads die
after 100 seconds of inactivity.
A given job may only be in the queue at once, so don't add it twice.
A single job will never have more than one worker assigned to it, which means that
if you have a job that takes 15 seconds to complete, and you schedule it to run
every 10 seconds, effectively it will only run every 20 seconds. Because after the
first time it is run, it will be busy when it's next scheduled time arrives.
If multiple jobs are scheduled to go off at the same time, it is undefined which one
will go off first.
|
Constructor Summary |
protected |
CronTab()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
instance
protected static CronTab instance
CronTab
protected CronTab()
addJob
public static CronJob addJob(String cronSpec,
Runnable r)
addJob
public static void addJob(CronJob job)
removeJob
public static void removeJob(CronJob job)
getInstance
protected static CronTab getInstance()
setInstance
protected static void setInstance(CronTab tab)
addJobInternal
protected void addJobInternal(CronJob job)
removeJobInternal
protected void removeJobInternal(CronJob job)
start
protected void start()
stop
protected void stop()
waitJobs
protected void waitJobs()
throws InterruptedException
- Throws:
InterruptedException
waitNextPeriod
protected void waitNextPeriod()
throws InterruptedException
- Throws:
InterruptedException
runNextJob
protected void runNextJob()
throws InterruptedException
- Throws:
InterruptedException
run
public void run()
- Specified by:
run in interface Runnable
pushWorker
protected void pushWorker(thinkmap.server.cron.CronTab.Worker thread)
popWorker
protected thinkmap.server.cron.CronTab.Worker popWorker()
main
public static void main(String[] args)
Copyright © 2013 Thinkmap, Inc. All Rights Reserved.