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.
showLineNumbers
1public MigrationTask() {2/* Run repeatedly with a delayed start */3task.schedule(3600.0);4}
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.
showLineNumbers
1public MigrationTask() {2/* Run repeatedly, delaying for one hour after a single execution of the task */3task.scheduleWithFixedDelay(0,3600.0);4}
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.
showLineNumbers
1public MigrationTask() {2/* Run repeatedly with one-hour execution and delay periods */3task.scheduleAtFixedRate(0,3600.0);4}