net.sf.basedb.util.timer
Class Scheduler
java.lang.Object
net.sf.basedb.util.timer.Scheduler
public class Scheduler
- extends Object
This class is a cousin to the standard 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.
- Version:
- 2.0
- Author:
- nicklas
- See Also:
Timer
,
TimerTask
,
ThreadTimerTask
- Last modified
- $Date: 2008-09-11 22:08:14 +0200 (Thu, 11 Sep 2008) $
Constructor Summary |
Scheduler(Timer timer,
boolean newThreads)
Create a new scheduler object. |
Method Summary |
private TimerTask |
getTimerTask(TimerTask task,
boolean allowMultiple)
|
TimerTask |
schedule(TimerTask task,
Date time,
boolean allowMultiple)
|
TimerTask |
schedule(TimerTask task,
Date firstTime,
long period,
boolean allowMultiple)
|
TimerTask |
schedule(TimerTask task,
long delay,
boolean allowMultiple)
|
TimerTask |
schedule(TimerTask task,
long delay,
long period,
boolean allowMultiple)
|
TimerTask |
scheduleAtFixedRate(TimerTask task,
Date firstTime,
long period,
boolean allowMultiple)
|
TimerTask |
scheduleAtFixedRate(TimerTask task,
long delay,
long period,
boolean allowMultiple)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
timer
private final Timer timer
newThreads
private final boolean newThreads
Scheduler
public Scheduler(Timer timer,
boolean newThreads)
- Create a new scheduler object.
- Parameters:
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 thread
getTimerTask
private TimerTask getTimerTask(TimerTask task,
boolean allowMultiple)
schedule
public TimerTask schedule(TimerTask task,
Date time,
boolean allowMultiple)
- See Also:
Timer.schedule(TimerTask, Date)
schedule
public TimerTask schedule(TimerTask task,
Date firstTime,
long period,
boolean allowMultiple)
- See Also:
Timer.schedule(TimerTask, Date, long)
schedule
public TimerTask schedule(TimerTask task,
long delay,
boolean allowMultiple)
- See Also:
Timer.schedule(TimerTask, long)
schedule
public TimerTask schedule(TimerTask task,
long delay,
long period,
boolean allowMultiple)
- See Also:
Timer.schedule(TimerTask, long, long)
scheduleAtFixedRate
public TimerTask scheduleAtFixedRate(TimerTask task,
Date firstTime,
long period,
boolean allowMultiple)
- See Also:
Timer.scheduleAtFixedRate(TimerTask, Date, long)
scheduleAtFixedRate
public TimerTask scheduleAtFixedRate(TimerTask task,
long delay,
long period,
boolean allowMultiple)
- See Also:
Timer.scheduleAtFixedRate(TimerTask, long, long)