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, Kim Sumin
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe default 'initialInterval' value - 100 millisecs.static final longThe default maximum backoff time (30 seconds).static final doubleThe default 'multiplier' value - value 2 (100% increase per backoff).protected final org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbackOff(BackOffContext backOffContext) Pause for the current backoff interval.protected voidcloneValues(ExponentialBackOffPolicy target) longThe initial period to sleep on the first backoff.longThe maximum interval to sleep for.doubleThe multiplier to use to generate the next backoff interval from the last.voidinitialIntervalSupplier(Supplier<Long> initialIntervalSupplier) Set the initial sleep interval value.voidmaxIntervalSupplier(Supplier<Long> maxIntervalSupplier) Setter for maximum back off period.voidmultiplierSupplier(Supplier<Double> multiplierSupplier) Set the multiplier value.protected ExponentialBackOffPolicyvoidsetInitialInterval(long initialInterval) Set the initial sleep interval value.voidsetMaxInterval(long maxInterval) Setter for maximum back off period.voidsetMultiplier(double multiplier) Set the multiplier value.voidsetSleeper(Sleeper sleeper) Public setter for theSleeperstrategy.start(RetryContext context) Returns a new instance ofBackOffContextwith 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 theSleeperstrategy.- Parameters:
sleeper- the sleeper to set defaults toThreadWaitSleeper.
-
withSleeper
Description copied from interface:SleepingBackOffPolicyClone the policy and return a new policy which uses the passed sleeper.- Specified by:
withSleeperin 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 is100millisecond. 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 supplies100millisecond.- 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 ofBackOffContextwith the configured properties.- Specified by:
startin interfaceBackOffPolicy- Parameters:
context- theRetryContextcontext, which might contain information that we can use to decide how to proceed.- Returns:
- the implementation-specific
BackOffContextor 'null'.
-
backOff
Pause for the current backoff interval.- Specified by:
backOffin interfaceBackOffPolicy- Parameters:
backOffContext- theBackOffContext- Throws:
BackOffInterruptedException- if the attempt at back off is interrupted.
-
toString
-