Class ExponentialBackOffTrigger

  • All Implemented Interfaces:
    org.springframework.scheduling.Trigger

    @ThreadSafe
    public class ExponentialBackOffTrigger
    extends java.lang.Object
    implements org.springframework.scheduling.Trigger
    Trigger implementation whose scheduling delay grows exponentially based on a given factor. The delay is bound between some minimum and maximum. The delay can be relative to the previous task scheduling/execution/completion.
    Since:
    3.3.9
    • Constructor Detail

      • ExponentialBackOffTrigger

        public ExponentialBackOffTrigger​(ExponentialBackOffTriggerProperties properties)
        Constructor with properties. Loads all values during construction. I.e. does not respond to subsequent changes to property values dynamically.
        Parameters:
        properties - the properties
      • ExponentialBackOffTrigger

        public ExponentialBackOffTrigger​(ExponentialBackOffTrigger.DelayType delayType,
                                         long minDelay,
                                         long maxDelay,
                                         float factor)
        Constructor.
        Parameters:
        delayType - type of delay
        minDelay - minimum delay in milliseconds
        maxDelay - maximum delay in milliseconds
        factor - multiplier factor to grow the delay
        Throws:
        java.lang.IllegalArgumentException - if the minimum delay is smaller than 1, the max delay is smaller than the minimum, or the factor is not positive.
    • Method Detail

      • nextExecutionTime

        public java.util.Date nextExecutionTime​(org.springframework.scheduling.TriggerContext triggerContext)
        Specified by:
        nextExecutionTime in interface org.springframework.scheduling.Trigger
      • reset

        public void reset()
        Reset the delay to the minimum given at construction time. Example usage: if the trigger is used to slow down attempt to contact a remote service in case of error, then a successful request can invoke reset, ensuring the next attempt will not be delayed.