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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidPause for thesetMinBackOffPeriod(long).longThe maximum backoff period in milliseconds.longThe minimum backoff period in milliseconds.voidmaxBackOffPeriodSupplier(Supplier<Long> backOffPeriodSupplier) Set a supplier for the maximum back off period in milliseconds.voidminBackOffPeriodSupplier(Supplier<Long> backOffPeriodSupplier) Set a supplier for the minimum back off period in milliseconds.voidsetMaxBackOffPeriod(long backOffPeriod) Set the maximum back off period in milliseconds.voidsetMinBackOffPeriod(long backOffPeriod) Set the minimum back off period in milliseconds.voidsetSleeper(Sleeper sleeper) Public setter for theSleeperstrategy.toString()withSleeper(Sleeper sleeper) Clone the policy and return a new policy which uses the passed sleeper.Methods inherited from class org.springframework.retry.backoff.StatelessBackOffPolicy
backOff, startMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.retry.backoff.BackOffPolicy
backOff, start
-
Constructor Details
-
UniformRandomBackOffPolicy
public UniformRandomBackOffPolicy()
-
-
Method Details
-
withSleeper
Description copied from interface:SleepingBackOffPolicyClone the policy and return a new policy which uses the passed sleeper.- Specified by:
withSleeperin interfaceSleepingBackOffPolicy<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 setter for theSleeperstrategy.- Parameters:
sleeper- the sleeper to set defaults toThreadWaitSleeper.
-
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
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
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
Pause for thesetMinBackOffPeriod(long).- Specified by:
doBackOffin classStatelessBackOffPolicy- Throws:
BackOffInterruptedException- if interrupted during sleep.
-
toString
-