com.adventnet.utilities.scheduler
Class Scheduler

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.adventnet.utilities.scheduler.Scheduler

public class Scheduler
extends java.lang.Thread

A scheduler for running tasks in a Java VM. This class can be used to schedule a particular task at a specified time. This is basically to control effectively a number of tasks using a limited number of threads


Field Summary
(package private)  int MAX_THREADS
          The maximum numer of threads to be used in executing tasks for this scheduler
(package private)  int NUM_THREADS_STOPPED
           
(package private)  java.util.Vector ready_tasks
           
(package private)  java.util.Vector runnables
           
(package private) static boolean STOP_ALL
           
(package private)  boolean STOP_THIS
           
(package private) static int STOP_TIME_OUT
           
(package private)  java.util.Vector times
           
(package private) static int TOTAL_THREADS
           
(package private)  java.util.Vector workers
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY, values
 
Method Summary
 boolean cleanUp()
           
static Scheduler createScheduler(java.lang.String nam)
           
static Scheduler createScheduler(java.lang.String nam, int maxThreadNumber)
           
 void deregisterThisScheduler(java.lang.String nam)
           
static java.lang.String getConfFile()
           
static int getDefaultMaxThreads()
           
 int getMaxThreads()
           
(package private)  java.lang.Runnable getNextTask()
          get the next task ready to run
static Scheduler getScheduler(java.lang.String nam)
           
(package private)  java.lang.Runnable getTheWork()
          something to let this thread rest when nothing to do
static int getTotalThreads()
           
 void killScheduler()
          Stops and destroys the schduler and its worker threads Cannot reuse scheduler when this method is called
 void removeTask(java.lang.Runnable task)
          This methood is used to remove a task from being scheduled.
 boolean resumeAll()
           
 void run()
          The main thread which kicks off the task execution
 void scheduleTask(java.lang.Runnable task, java.util.Date when)
          This methood schedules a one-time task at the specified time
static void setConfFile(java.lang.String s)
           
static void setDefaultMaxThreads(int i)
           
 boolean setMaxThreads(int i)
           
 void setStopTimeout(int timeout)
           
(package private)  void startTask(java.lang.Runnable task)
          start the task
(package private)  void startWorkers()
          start the workers
static boolean stopAll()
           
 boolean stopThis()
           
(package private)  void waitSchedule()
           
 
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

MAX_THREADS

int MAX_THREADS
The maximum numer of threads to be used in executing tasks for this scheduler

TOTAL_THREADS

static int TOTAL_THREADS

STOP_ALL

static boolean STOP_ALL

STOP_THIS

boolean STOP_THIS

NUM_THREADS_STOPPED

int NUM_THREADS_STOPPED

runnables

java.util.Vector runnables

times

java.util.Vector times

workers

java.util.Vector workers

ready_tasks

java.util.Vector ready_tasks

STOP_TIME_OUT

static int STOP_TIME_OUT
Method Detail

getMaxThreads

public int getMaxThreads()

getDefaultMaxThreads

public static int getDefaultMaxThreads()

setDefaultMaxThreads

public static void setDefaultMaxThreads(int i)

setMaxThreads

public boolean setMaxThreads(int i)

getTotalThreads

public static int getTotalThreads()

getConfFile

public static java.lang.String getConfFile()

setConfFile

public static void setConfFile(java.lang.String s)

createScheduler

public static Scheduler createScheduler(java.lang.String nam)

createScheduler

public static Scheduler createScheduler(java.lang.String nam,
                                        int maxThreadNumber)

getScheduler

public static Scheduler getScheduler(java.lang.String nam)

scheduleTask

public void scheduleTask(java.lang.Runnable task,
                         java.util.Date when)
This methood schedules a one-time task at the specified time

removeTask

public void removeTask(java.lang.Runnable task)
This methood is used to remove a task from being scheduled.

resumeAll

public boolean resumeAll()

killScheduler

public void killScheduler()
Stops and destroys the schduler and its worker threads Cannot reuse scheduler when this method is called

stopAll

public static boolean stopAll()

stopThis

public boolean stopThis()

cleanUp

public boolean cleanUp()

setStopTimeout

public void setStopTimeout(int timeout)

getTheWork

java.lang.Runnable getTheWork()
something to let this thread rest when nothing to do

run

public void run()
The main thread which kicks off the task execution
Overrides:
run in class java.lang.Thread

waitSchedule

void waitSchedule()
            throws java.lang.InterruptedException

startTask

void startTask(java.lang.Runnable task)
start the task

getNextTask

java.lang.Runnable getNextTask()
get the next task ready to run

startWorkers

void startWorkers()
start the workers

deregisterThisScheduler

public void deregisterThisScheduler(java.lang.String nam)