com.perdues
Class Scheduler

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.perdues.Scheduler
All Implemented Interfaces:
java.lang.Runnable

public class Scheduler
extends java.lang.Thread

Class to support periodic jobs passed to it as Runnables. This will run each one at fixed intervals given in seconds. Spawns a new Thread for each job it runs. This class's interface is based on com.bitmechanic.util.Scheduler, written by James Cooper.

If you would like to run a task once per minute, implemented by an instance of MyRunnable, you need only do:

   Scheduler.defaultScheduler().scheduleJob(new MyRunnable(), 60);
 
It will run in a new Thread every 60 seconds.


Field Summary
static boolean debug
          Turn this flag on to receive debugging information on System.err.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Scheduler()
          Creates but does not start a new Scheduler.
 
Method Summary
static Scheduler defaultScheduler()
          Returns the default Scheduler, creating and starting it if this has not already been done.
 int getJobCount()
          Returns the number of periodic jobs currently managed by this Scheduler.
 void removeJob(java.lang.Runnable job)
          Removes a periodic job from the list.
 void run()
          Implementation of Runnable; not intended to be called directly from user code.
 void scheduleJob(java.lang.Runnable job, int sleepInterval)
          Adds a Runnable to this Scheduler, to be run every sleepInterval seconds.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

public static boolean debug
Turn this flag on to receive debugging information on System.err.
Constructor Detail

Scheduler

public Scheduler()
Creates but does not start a new Scheduler.
Method Detail

defaultScheduler

public static Scheduler defaultScheduler()
Returns the default Scheduler, creating and starting it if this has not already been done. The default Scheduler runs as a daemon thread. If all "user" (non-daemon) threads exit, the Java VM will exit also.

scheduleJob

public void scheduleJob(java.lang.Runnable job,
                        int sleepInterval)
Adds a Runnable to this Scheduler, to be run every sleepInterval seconds.

removeJob

public void removeJob(java.lang.Runnable job)
Removes a periodic job from the list.

run

public void run()
Implementation of Runnable; not intended to be called directly from user code. This is the main loop; waits for jobs to be ready to run and runs each in its own thread.
Overrides:
run in class java.lang.Thread

getJobCount

public int getJobCount()
Returns the number of periodic jobs currently managed by this Scheduler.