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 other) |
long |
getInitialDelay()
Return the initial delay, or 0 if none.
|
long |
getPeriod()
Return this trigger's period.
|
TimeUnit |
getTimeUnit()
Return this trigger's time unit (milliseconds by default).
|
int |
hashCode() |
boolean |
isFixedRate()
Return whether this trigger uses fixed rate (
true ) or
fixed delay (false ) behavior. |
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, @Nullable TimeUnit timeUnit)
setInitialDelay(long)
.public long getPeriod()
public TimeUnit getTimeUnit()
public void setInitialDelay(long initialDelay)
TimeUnit
. If no time unit was explicitly
provided upon instantiation, the default is milliseconds.public long getInitialDelay()
public void setFixedRate(boolean fixedRate)
public boolean isFixedRate()
true
) or
fixed delay (false
) behavior.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