public class PeriodicTrigger extends Object implements Trigger
true
.
Note that the TaskScheduler interface already defines methods for scheduling tasks at fixed-rate or with fixed-delay. Both also support an optional value for the initial delay. Those methods should be used directly whenever possible. The value of this Trigger implementation is that it can be used within components that rely on the Trigger abstraction. For example, it may be convenient to allow periodic triggers, cron-based triggers, and even custom Trigger implementations to be used interchangeably.
Constructor and Description |
---|
PeriodicTrigger(long period)
Create a trigger with the given period in milliseconds.
|
PeriodicTrigger(long period,
TimeUnit timeUnit)
Create a trigger with the given period and time unit.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
int |
hashCode() |
Date |
nextExecutionTime(TriggerContext triggerContext)
Returns the time after which a task should run again.
|
void |
setFixedRate(boolean fixedRate)
Specify whether the periodic interval should be measured between the
scheduled start times rather than between actual completion times.
|
void |
setInitialDelay(long initialDelay)
Specify the delay for the initial execution.
|
public PeriodicTrigger(long period)
public PeriodicTrigger(long period, TimeUnit timeUnit)
setInitialDelay(long)
.public void setInitialDelay(long initialDelay)
TimeUnit
. If no time unit was explicitly
provided upon instantiation, the default is milliseconds.public void setFixedRate(boolean fixedRate)
public Date nextExecutionTime(TriggerContext triggerContext)
nextExecutionTime
in interface Trigger
triggerContext
- context object encapsulating last execution times
and last completion timenull
if the trigger won't fire anymore