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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Pause for thesetMinBackOffPeriod(long)
.long
The maximum backoff period in milliseconds.long
The minimum backoff period in milliseconds.void
maxBackOffPeriodSupplier
(Supplier<Long> backOffPeriodSupplier) Set a supplier for the maximum back off period in milliseconds.void
minBackOffPeriodSupplier
(Supplier<Long> backOffPeriodSupplier) Set a supplier for the minimum back off period in milliseconds.void
setMaxBackOffPeriod
(long backOffPeriod) Set the maximum back off period in milliseconds.void
setMinBackOffPeriod
(long backOffPeriod) Set the minimum back off period in milliseconds.void
setSleeper
(Sleeper sleeper) Public setter for theSleeper
strategy.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, start
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.retry.backoff.BackOffPolicy
backOff, start
-
Constructor Details
-
UniformRandomBackOffPolicy
public UniformRandomBackOffPolicy()
-
-
Method Details
-
withSleeper
Description copied from interface:SleepingBackOffPolicy
Clone the policy and return a new policy which uses the passed sleeper.- Specified by:
withSleeper
in 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 theSleeper
strategy.- 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:
doBackOff
in classStatelessBackOffPolicy
- Throws:
BackOffInterruptedException
- if interrupted during sleep.
-
toString
-