spring-framework / org.springframework.scheduling.support / PeriodicTrigger

PeriodicTrigger

open class PeriodicTrigger : Trigger

A trigger for periodic task execution. The period may be applied as either fixed-rate or fixed-delay, and an initial delay value may also be configured. The default initial delay is 0, and the default behavior is fixed-delay (i.e. the interval between successive executions is measured from each completion time). To measure the interval between the scheduled start time of each execution instead, set the 'fixedRate' property to 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.

Author
Mark Fisher

Since
3.0

Constructors

<init>

PeriodicTrigger(period: Long)

Create a trigger with the given period in milliseconds.

PeriodicTrigger(period: Long, timeUnit: TimeUnit)

Create a trigger with the given period and time unit. The time unit will apply not only to the period but also to any 'initialDelay' value, if configured on this Trigger later via #setInitialDelay(long).

Functions

equals

open fun equals(other: Any?): Boolean

getInitialDelay

open fun getInitialDelay(): Long

Return the initial delay, or 0 if none.

getPeriod

open fun getPeriod(): Long

Return this trigger's period.

getTimeUnit

open fun getTimeUnit(): TimeUnit

Return this trigger's time unit (milliseconds by default).

hashCode

open fun hashCode(): Int

isFixedRate

open fun isFixedRate(): Boolean

Return whether this trigger uses fixed rate (true) or fixed delay (false) behavior.

nextExecutionTime

open fun nextExecutionTime(triggerContext: TriggerContext): Date

Returns the time after which a task should run again.

setFixedRate

open fun setFixedRate(fixedRate: Boolean): Unit

Specify whether the periodic interval should be measured between the scheduled start times rather than between actual completion times. The latter, "fixed delay" behavior, is the default.

setInitialDelay

open fun setInitialDelay(initialDelay: Long): Unit

Specify the delay for the initial execution. It will be evaluated in terms of this trigger's TimeUnit. If no time unit was explicitly provided upon instantiation, the default is milliseconds.