Class Scheduler
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.log4j.component.scheduler.Scheduler
-
- All Implemented Interfaces:
java.lang.Runnable
public class Scheduler extends java.lang.Thread
A simple but still useful implementation of a Scheduler (in memory only). 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Scheduler.ScheduledJobEntry
Represents an entry in job scheduler.
-
Constructor Summary
Constructors Constructor Description Scheduler()
Create new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
changePeriod(Job job, long newPeriod)
Change the period of a job.boolean
delete(Job job)
Delete the given job.(package private) void
executeInABox(Job job)
We do not want a single failure to affect the whole scheduler.(package private) int
findIndex(Job job)
Find the index of a given job.(package private) void
linger()
Wait for notification.(package private) void
linger(long timeToLinger)
Wait for notification or time to elapse.void
run()
Run scheduler.void
schedule(Job job, long desiredTime)
Schedule aJob
for execution at system time given by thedesiredTime
parameter.void
schedule(Job job, long desiredTime, long period)
Schedule aJob
for execution at system time given by thedesiredTime
parameter.private void
schedule(Scheduler.ScheduledJobEntry newSJE)
Schedule a job.void
shutdown()
Shut down scheduler.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Method Detail
-
findIndex
int findIndex(Job job)
Find the index of a given job.- Parameters:
job
- job- Returns:
- -1 if the job could not be found.
-
delete
public boolean delete(Job job)
Delete the given job.- Parameters:
job
- job.- Returns:
- true if the job could be deleted, and false if the job could not be found or if the Scheduler is about to shutdown in which case deletions are not permitted.
-
schedule
public void schedule(Job job, long desiredTime)
Schedule aJob
for execution at system time given by thedesiredTime
parameter.- Parameters:
job
- job to schedule.desiredTime
- desired time of execution.
-
schedule
public void schedule(Job job, long desiredTime, long period)
Schedule aJob
for execution at system time given by thedesiredTime
parameter. The job will be rescheduled. It will execute with a frequency determined by the period parameter.- Parameters:
job
- job to schedule.desiredTime
- desired time of execution.period
- repeat period.
-
changePeriod
public boolean changePeriod(Job job, long newPeriod)
Change the period of a job. The original job must exist for its period to be changed. The method returns true if the period could be changed, and false otherwise.- Parameters:
job
- job.newPeriod
- new repeat period.- Returns:
- true if period could be changed.
-
schedule
private void schedule(Scheduler.ScheduledJobEntry newSJE)
Schedule a job.- Parameters:
newSJE
- new job entry.
-
shutdown
public void shutdown()
Shut down scheduler.
-
run
public void run()
Run scheduler.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
executeInABox
void executeInABox(Job job)
We do not want a single failure to affect the whole scheduler.- Parameters:
job
- job to execute.
-
linger
void linger()
Wait for notification.
-
linger
void linger(long timeToLinger)
Wait for notification or time to elapse.- Parameters:
timeToLinger
- time to linger.
-
-