public class Scheduler extends Thread
This implementation will work very well when the number of scheduled job is small, say less than 100 jobs. If a larger number of events need to be scheduled, than a better adapted data structure for the jobList can give improved performance.
Thread.State, Thread.UncaughtExceptionHandler
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
Scheduler()
Create new instance.
|
Modifier and Type | Method and Description |
---|---|
boolean |
changePeriod(Job job,
long newPeriod)
Change the period of a job.
|
boolean |
delete(Job job)
Delete the given job.
|
void |
run()
Run scheduler.
|
void |
schedule(Job job,
long desiredTime)
Schedule a
Job for execution at system time given by
the desiredTime parameter. |
void |
schedule(Job job,
long desiredTime,
long period)
Schedule a
Job for execution at system time given by
the desiredTime parameter. |
void |
shutdown()
Shut down scheduler.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public boolean delete(Job job)
job
- job.public void schedule(Job job, long desiredTime)
Job
for execution at system time given by
the desiredTime
parameter.job
- job to schedule.desiredTime
- desired time of execution.public void schedule(Job job, long desiredTime, long period)
Job
for execution at system time given by
the desiredTime
parameter.
The job will be rescheduled. It will execute with a frequency determined by the period parameter.
job
- job to schedule.desiredTime
- desired time of execution.period
- repeat period.public boolean changePeriod(Job job, long newPeriod)
The method returns true if the period could be changed, and false otherwise.
job
- job.newPeriod
- new repeat period.public void shutdown()
Copyright © 2013 The Apache Software Foundation. Licensed under the Apache License, Version 2.0
Apache Extras for Apache log4j, Apache log4j and Apache are trademarks of the Apache Software Foundation.