Class UniformRandomBackOffPolicy

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

public class UniformRandomBackOffPolicy extends StatelessBackOffPolicy implements SleepingBackOffPolicy<UniformRandomBackOffPolicy>
Implementation of BackOffPolicy that pauses for a random period of time before continuing. A pause is implemented using Sleeper.sleep(long). setMinBackOffPeriod(long) is thread-safe and it is safe to call setMaxBackOffPeriod(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, Tomaz Fernandes, Marius Lichtblau
  • Constructor Details

    • UniformRandomBackOffPolicy

      public UniformRandomBackOffPolicy()
  • Method Details

    • withSleeper

      public UniformRandomBackOffPolicy 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<UniformRandomBackOffPolicy>
      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.
    • setMinBackOffPeriod

      public void setMinBackOffPeriod(long backOffPeriod)
      Set the minimum back off period in milliseconds. Cannot be < 1. Default value is 500ms.
      Parameters:
      backOffPeriod - the backoff period
    • minBackOffPeriodSupplier

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

      public long getMinBackOffPeriod()
      The minimum backoff period in milliseconds.
      Returns:
      the backoff period
    • setMaxBackOffPeriod

      public void setMaxBackOffPeriod(long backOffPeriod)
      Set the maximum back off period in milliseconds. Cannot be < 1. Default value is 1500ms.
      Parameters:
      backOffPeriod - the back off period
    • maxBackOffPeriodSupplier

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

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

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

      public String toString()
      Overrides:
      toString in class Object