Schedule tasks
The com.psddev.dari.util.Task class includes the following schedule methods to start a task at a specified time and to run it in periodic intervals. Unlike the submit method that runs a task one time and stops it, the schedule methods run the task repeatedly until it is manually stopped with the Task Status tool.
schedule(double initialDelay)runs a task with a delayed start and without pause. The schedule method below runs the task one hour after it is started. IfinitialDelayis zero, then the task starts immediately.
public MigrationTask() {
/* Run repeatedly with a delayed start */
task.schedule(3600.0);
}
scheduleWithFixedDelay(double initialDelay, double periodicDelay)runs a task with a delayed start, with a periodic delay, and with a single execution of the task between delays. ThescheduleWithFixedDelaymethod below starts the task immediately, executes thedoTaskmethod one time, delays execution for one hour, then repeats the execution-delay pattern.
public MigrationTask() {
/* Run repeatedly, delaying for one hour after a single execution of the task */
task.scheduleWithFixedDelay(0,3600.0);
}
scheduleAtFixedRate(double initialDelay, double periodicDelay)runs a task with a delayed start and with fixed execution and delay times. ThescheduleAtFixedRatemethod below starts the task immediately, repeatedly executesdoTaskfor one hour, delays execution for one hour, then repeats the execution-delay pattern.
public MigrationTask() {
/* Run repeatedly with one-hour execution and delay periods */
task.scheduleAtFixedRate(0,3600.0);
}