Class ExponentialBackOffPolicy
java.lang.Object
org.springframework.retry.backoff.ExponentialBackOffPolicy
- All Implemented Interfaces:
BackOffPolicy
,SleepingBackOffPolicy<ExponentialBackOffPolicy>
- Direct Known Subclasses:
ExponentialRandomBackOffPolicy
public class ExponentialBackOffPolicy
extends Object
implements SleepingBackOffPolicy<ExponentialBackOffPolicy>
Implementation of
BackOffPolicy
that increases the back off period for each
retry attempt in a given set up to a limit.
This implementation is thread-safe and suitable for concurrent access. Modifications to
the configuration do not affect any retry sets that are already in progress.
The setInitialInterval(long)
property controls the initial delay value for the
first retry and the setMultiplier(double)
property controls by how much the
delay is increased for each subsequent attempt. The delay interval is capped at
setMaxInterval(long)
.- Author:
- Rob Harrop, Dave Syer, Gary Russell, Artem Bilan, Marius Lichtblau, Anton Aharkau
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
The default 'initialInterval' value - 100 millisecs.static final long
The default maximum backoff time (30 seconds).static final double
The default 'multiplier' value - value 2 (100% increase per backoff).protected final org.apache.commons.logging.Log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
backOff
(BackOffContext backOffContext) Pause for the current backoff interval.protected void
cloneValues
(ExponentialBackOffPolicy target) long
The initial period to sleep on the first backoff.long
The maximum interval to sleep for.double
The multiplier to use to generate the next backoff interval from the last.void
initialIntervalSupplier
(Supplier<Long> initialIntervalSupplier) Set the initial sleep interval value.void
maxIntervalSupplier
(Supplier<Long> maxIntervalSupplier) Setter for maximum back off period.void
multiplierSupplier
(Supplier<Double> multiplierSupplier) Set the multiplier value.protected ExponentialBackOffPolicy
void
setInitialInterval
(long initialInterval) Set the initial sleep interval value.void
setMaxInterval
(long maxInterval) Setter for maximum back off period.void
setMultiplier
(double multiplier) Set the multiplier value.void
setSleeper
(Sleeper sleeper) Public setter for theSleeper
strategy.start
(RetryContext context) Returns a new instance ofBackOffContext
with the configured properties.toString()
withSleeper
(Sleeper sleeper) Clone the policy and return a new policy which uses the passed sleeper.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log logger -
DEFAULT_INITIAL_INTERVAL
public static final long DEFAULT_INITIAL_INTERVALThe default 'initialInterval' value - 100 millisecs. Coupled with the default 'multiplier' value this gives a useful initial spread of pauses for 1-5 retries.- See Also:
-
DEFAULT_MAX_INTERVAL
public static final long DEFAULT_MAX_INTERVALThe default maximum backoff time (30 seconds).- See Also:
-
DEFAULT_MULTIPLIER
public static final double DEFAULT_MULTIPLIERThe default 'multiplier' value - value 2 (100% increase per backoff).- See Also:
-
-
Constructor Details
-
ExponentialBackOffPolicy
public ExponentialBackOffPolicy()
-
-
Method Details
-
setSleeper
Public setter for theSleeper
strategy.- Parameters:
sleeper
- the sleeper to set defaults toThreadWaitSleeper
.
-
withSleeper
Description copied from interface:SleepingBackOffPolicy
Clone the policy and return a new policy which uses the passed sleeper.- Specified by:
withSleeper
in interfaceSleepingBackOffPolicy<ExponentialBackOffPolicy>
- 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
-
newInstance
-
cloneValues
-
setInitialInterval
public void setInitialInterval(long initialInterval) Set the initial sleep interval value. Default is100
millisecond. Cannot be set to a value less than one.- Parameters:
initialInterval
- the initial interval
-
setMultiplier
public void setMultiplier(double multiplier) Set the multiplier value. Default is '2.0
'. Hint: do not use values much in excess of 1.0 (or the backoff will get very long very fast).- Parameters:
multiplier
- the multiplier
-
setMaxInterval
public void setMaxInterval(long maxInterval) Setter for maximum back off period. Default is 30000 (30 seconds). the value will be reset to 1 if this method is called with a value less than 1. Set this to avoid infinite waits if backing off a large number of times (or if the multiplier is set too high).- Parameters:
maxInterval
- in milliseconds.
-
initialIntervalSupplier
Set the initial sleep interval value. Default supplier supplies100
millisecond.- Parameters:
initialIntervalSupplier
- the initial interval- Since:
- 2.0
-
multiplierSupplier
Set the multiplier value. Default supplier supplies '2.0
'. Hint: do not use values much in excess of 1.0 (or the backoff will get very long very fast).- Parameters:
multiplierSupplier
- the multiplier- Since:
- 2.0
-
maxIntervalSupplier
Setter for maximum back off period. Default is 30000 (30 seconds). the value will be reset to 1 if this method is called with a value less than 1. Set this to avoid infinite waits if backing off a large number of times (or if the multiplier is set too high).- Parameters:
maxIntervalSupplier
- in milliseconds.- Since:
- 2.0
-
getInitialIntervalSupplier
-
getMaxIntervalSupplier
-
getMultiplierSupplier
-
getInitialInterval
public long getInitialInterval()The initial period to sleep on the first backoff.- Returns:
- the initial interval
-
getMaxInterval
public long getMaxInterval()The maximum interval to sleep for. Defaults to 30 seconds.- Returns:
- the maximum interval.
-
getMultiplier
public double getMultiplier()The multiplier to use to generate the next backoff interval from the last.- Returns:
- the multiplier in use
-
start
Returns a new instance ofBackOffContext
with the configured properties.- Specified by:
start
in interfaceBackOffPolicy
- Parameters:
context
- theRetryContext
context, which might contain information that we can use to decide how to proceed.- Returns:
- the implementation-specific
BackOffContext
or 'null
'.
-
backOff
Pause for the current backoff interval.- Specified by:
backOff
in interfaceBackOffPolicy
- Parameters:
backOffContext
- theBackOffContext
- Throws:
BackOffInterruptedException
- if the attempt at back off is interrupted.
-
toString
-