public class RunAtFixedRate extends Object implements JobScheduler
JobScheduler
that executes its Job
repeatedly at a fixed time.
The RunAtFixedRate JobScheduler works with minute precision. You can set an initial start time
with setHourOfDay(int)
and setMinuteOfHour(int)
.
The lapse of time between successive runs of the submitted Job can be set
with setPeriod(int)
.
In the following examples myJob
is an instance of a Job
implementation.
Example: Run a Job every 10 minutes.
RunAtFixedRate runAtFixedRate = new RunAtFixedRate(); runAtFixedRate.setPeriod(10); runAtFixedRate.schedule(myJob);This wil execute
myJob
on every multiple of 10 minutes, starting from the next multiple of
10 minutes past the whole hour. This is because in our code snippet we didn't touch start time and so initial
start time was counted from 00.00h. If the execution of myJob
takes longer then the 10-minute
period, the next execution will take place immediately after the ending of the previous one.
Example: Run a Job at 06.42 every day.
RunAtFixedRate runAtFixedRate = new RunAtFixedRate(); runAtFixedRate.setHourOfDay(6); runAtFixedRate.setMinuteOfHour(42); runAtFixedRate.setPeriod(24 * 60); runAtFixedRate.schedule(myJob);This will execute
myJob
every day at 06.42, starting from the first occasion counted from now.
The scheduler can be stopped gracefully by creating a file 'cfg/stop', relative to the working directory. Upon detection, a currently executing job will be left to finish first, after which the scheduler will stop.
Constructor and Description |
---|
RunAtFixedRate() |
Modifier and Type | Method and Description |
---|---|
int |
getHourOfDay() |
int |
getMaxErrorCount() |
int |
getMinuteOfHour() |
int |
getPeriod() |
void |
schedule(Job job) |
void |
setHourOfDay(int hourOfDay) |
void |
setMaxErrorCount(int maxErrorCount) |
void |
setMinuteOfHour(int minuteOfHour) |
void |
setPeriod(int period) |
public int getMaxErrorCount()
public void setMaxErrorCount(int maxErrorCount)
public int getPeriod()
public void setPeriod(int period)
public int getHourOfDay()
public void setHourOfDay(int hourOfDay)
public int getMinuteOfHour()
public void setMinuteOfHour(int minuteOfHour)
public void schedule(Job job) throws Exception
schedule
in interface JobScheduler
Exception
Copyright © 2017. All rights reserved.