public class PeriodicTrigger extends java.lang.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,
java.util.concurrent.TimeUnit timeUnit)
Create a trigger with the given period and time unit.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
long |
getInitialDelay()
Return the initial delay, or 0 if none.
|
long |
getPeriod()
Return this trigger's period.
|
java.util.concurrent.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. |
java.util.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 java.util.concurrent.TimeUnit timeUnit)
setInitialDelay(long)
.public long getPeriod()
public java.util.concurrent.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 java.util.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 anymorepublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object