public class Scheduler
extends java.lang.Object
Timer
class
but only allows scheduling of tasks. This allows an application to
create a core timer and let other code add TimerTask
:s to
the timer.
Another feature of this class is that it can force the execution of tasks in their own threads. This avoids that long-runing tasks hog the timer thread and therby prevent other tasks from running.
If new threads are created for the tasks, it is also possible to specify on a task-by-task basis if the task may run in multiple threads at the same time.
A side-effect by using a scheduler is that all methods may return
a different TimerTask
object than what was scheduled.
If the calling application want to cancel a task it must do so on
the object that is returned, since that object is the one really lives
in the timer. However, calling TimerTask.cancel()
passes through
to the original task as well.
Timer
,
TimerTask
,
ThreadTimerTask
Modifier and Type | Field and Description |
---|---|
private boolean |
newThreads |
private java.util.Timer |
timer |
Constructor and Description |
---|
Scheduler(java.util.Timer timer,
boolean newThreads)
Create a new scheduler object.
|
Modifier and Type | Method and Description |
---|---|
private java.util.TimerTask |
getTimerTask(java.util.TimerTask task,
boolean allowMultiple) |
java.util.TimerTask |
schedule(java.util.TimerTask task,
java.util.Date time,
boolean allowMultiple) |
java.util.TimerTask |
schedule(java.util.TimerTask task,
java.util.Date firstTime,
long period,
boolean allowMultiple) |
java.util.TimerTask |
schedule(java.util.TimerTask task,
long delay,
boolean allowMultiple) |
java.util.TimerTask |
schedule(java.util.TimerTask task,
long delay,
long period,
boolean allowMultiple) |
java.util.TimerTask |
scheduleAtFixedRate(java.util.TimerTask task,
java.util.Date firstTime,
long period,
boolean allowMultiple) |
java.util.TimerTask |
scheduleAtFixedRate(java.util.TimerTask task,
long delay,
long period,
boolean allowMultiple) |
public Scheduler(java.util.Timer timer, boolean newThreads)
timer
- The underlying timer object which handles the execution of the tasksnewThreads
- If TRUE, each task is started in it's own thread, if FALSE
the tasks are executed in the timers threadprivate java.util.TimerTask getTimerTask(java.util.TimerTask task, boolean allowMultiple)
public java.util.TimerTask schedule(java.util.TimerTask task, java.util.Date time, boolean allowMultiple)
Timer.schedule(TimerTask, Date)
public java.util.TimerTask schedule(java.util.TimerTask task, java.util.Date firstTime, long period, boolean allowMultiple)
Timer.schedule(TimerTask, Date, long)
public java.util.TimerTask schedule(java.util.TimerTask task, long delay, boolean allowMultiple)
Timer.schedule(TimerTask, long)
public java.util.TimerTask schedule(java.util.TimerTask task, long delay, long period, boolean allowMultiple)
Timer.schedule(TimerTask, long, long)
public java.util.TimerTask scheduleAtFixedRate(java.util.TimerTask task, java.util.Date firstTime, long period, boolean allowMultiple)
Timer.scheduleAtFixedRate(TimerTask, Date, long)
public java.util.TimerTask scheduleAtFixedRate(java.util.TimerTask task, long delay, long period, boolean allowMultiple)
Timer.scheduleAtFixedRate(TimerTask, long, long)