|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread com.cosylab.util.Scheduler
public class Scheduler
Scheduler implementation that prevents single tasks from locking up entire scheduler. This implementation tries to use minimal number of threads to execute given tasks.
Tasks are scheduled using a priority queue, sorted by next execution time.
Time is measured using wait method, so it is bound to be incorrect. This
implementation is not suitable for scheduling times below 10ms, but it
depends on platform (limits are about 50ms for Windows9x, 10ms for Windows
2000/XP/NT and 1ms for Linux/Unix).
Each task will run only once at any given time (if task is scheduled to be
executed every 10ms, but it takes 100ms to run, same task will not be
executed 10 times in between).
If a task exceeds its next scheduled execution time while running, next
execution time will be assigned by adding
SchedulerTask.getInterval()
after current task has completed.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary |
---|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
Scheduler()
Creates new scheduler and starts it. |
|
Scheduler(int minimumRunners)
Creates a new scheduler and specifies the minimum number of runner threads alive, regardless the number of tasks. |
|
Scheduler(int min,
int max)
|
Method Summary | |
---|---|
void |
cancel()
Cancels all tasks, runners and stops the scheduler. |
protected void |
returnRunner(com.cosylab.util.Scheduler.SchedulerRunner runner)
Returns runner to the pool. |
protected void |
returnTask(com.cosylab.util.Scheduler.TaskEntry task)
Puts task back to the queue. |
void |
run()
Main loop that executes tasks. |
void |
schedule(SchedulerTask task)
Schedule new task for immediate single time execution. |
void |
schedule(SchedulerTask task,
long delay,
boolean repeated)
Schedule task for delayed execution. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, 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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Scheduler()
public Scheduler(int minimumRunners)
minimumRunners
- Number of threads.public Scheduler(int min, int max)
Method Detail |
---|
protected void returnRunner(com.cosylab.util.Scheduler.SchedulerRunner runner)
runner
- Runner thread to return to pool.protected void returnTask(com.cosylab.util.Scheduler.TaskEntry task)
task
- Task to return.public void schedule(SchedulerTask task)
task
- Task to schedule.public void schedule(SchedulerTask task, long delay, boolean repeated)
task
- Task to scheduledelay
- Delay before initial execution.repeated
- Should this task be repeated or executed only once.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
Runnable.run()
public void cancel()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |