Schedule tasks
The 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. IfinitialDelay
is 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. ThescheduleWithFixedDelay
method below starts the task immediately, executes thedoTask
method 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. ThescheduleAtFixedRate
method below starts the task immediately, repeatedly executesdoTask
for 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);
}
Previous Topic
Creating a background task
Next Topic
Repeating tasks