Class FixedBackOffPolicy

java.lang.Object
org.springframework.retry.backoff.StatelessBackOffPolicy
org.springframework.retry.backoff.FixedBackOffPolicy
All Implemented Interfaces:
BackOffPolicy, SleepingBackOffPolicy<FixedBackOffPolicy>

public class FixedBackOffPolicy extends StatelessBackOffPolicy implements SleepingBackOffPolicy<FixedBackOffPolicy>
Implementation of BackOffPolicy that pauses for a fixed period of time before continuing. A pause is implemented using Sleeper.sleep(long). setBackOffPeriod(long) is thread-safe and it is safe to call setBackOffPeriod(long) during execution from multiple threads, however this may cause a single retry operation to have pauses of different intervals.
Author:
Rob Harrop, Dave Syer, Artem Bilan, Marius Lichtblau
  • Constructor Details

    • FixedBackOffPolicy

      public FixedBackOffPolicy()
  • Method Details

    • withSleeper

      public FixedBackOffPolicy withSleeper(Sleeper sleeper)
      Description copied from interface: SleepingBackOffPolicy
      Clone the policy and return a new policy which uses the passed sleeper.
      Specified by:
      withSleeper in interface SleepingBackOffPolicy<FixedBackOffPolicy>
      Parameters:
      sleeper - Target to be invoked any time the backoff policy sleeps
      Returns:
      a clone of this policy which will have all of its backoff sleeps routed into the passed sleeper
    • setSleeper

      public void setSleeper(Sleeper sleeper)
      Public setter for the Sleeper strategy.
      Parameters:
      sleeper - the sleeper to set defaults to ThreadWaitSleeper.
    • setBackOffPeriod

      public void setBackOffPeriod(long backOffPeriod)
      Set the back off period in milliseconds. Cannot be < 1. Default value is 1000ms.
      Parameters:
      backOffPeriod - the back off period
    • backOffPeriodSupplier

      public void backOffPeriodSupplier(Supplier<Long> backOffPeriodSupplier)
      Set a supplier for the back off period in milliseconds. Cannot be < 1. Default supplier supplies 1000ms.
      Parameters:
      backOffPeriodSupplier - the back off period
      Since:
      2.0
    • getBackOffPeriod

      public long getBackOffPeriod()
      The backoff period in milliseconds.
      Returns:
      the backoff period
    • doBackOff

      protected void doBackOff() throws BackOffInterruptedException
      Pause for the setBackOffPeriod(long).
      Specified by:
      doBackOff in class StatelessBackOffPolicy
      Throws:
      BackOffInterruptedException - if interrupted during sleep.
    • toString

      public String toString()
      Overrides:
      toString in class Object