Class ExponentialRandomBackOffPolicy
java.lang.Object
org.springframework.retry.backoff.ExponentialBackOffPolicy
org.springframework.retry.backoff.ExponentialRandomBackOffPolicy
- All Implemented Interfaces:
BackOffPolicy
,SleepingBackOffPolicy<ExponentialBackOffPolicy>
Implementation of
ExponentialBackOffPolicy
that chooses a random multiple of the interval that would come from a simple
deterministic exponential. The random multiple is uniformly distributed between 1 and
the deterministic multiplier (so in practice the interval is somewhere between the next
and next but one intervals in the deterministic case). This is often referred to as
jitter.
This has shown to at least be useful in testing scenarios where excessive contention is
generated by the test needing many retries. In test, usually threads are started at the
same time, and thus stomp together onto the next interval. Using this
BackOffPolicy
can help avoid that scenario.
Example: initialInterval = 50 multiplier = 2.0 maxInterval = 3000 numRetries = 5
ExponentialBackOffPolicy
yields: [50, 100, 200, 400, 800]
ExponentialRandomBackOffPolicy
may yield [76, 151, 304, 580, 901] or [53, 190,
267, 451, 815] (random distributed values within the ranges of [50-100, 100-200,
200-400, 400-800, 800-1600])- Author:
- Jon Travis, Dave Syer, Chase Diem
-
Field Summary
Fields inherited from class org.springframework.retry.backoff.ExponentialBackOffPolicy
DEFAULT_INITIAL_INTERVAL, DEFAULT_MAX_INTERVAL, DEFAULT_MULTIPLIER, logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected ExponentialBackOffPolicy
start
(RetryContext context) Returns a new instance ofBackOffContext
, seeded with this policies settings.Methods inherited from class org.springframework.retry.backoff.ExponentialBackOffPolicy
backOff, cloneValues, getInitialInterval, getInitialIntervalSupplier, getMaxInterval, getMaxIntervalSupplier, getMultiplier, getMultiplierSupplier, initialIntervalSupplier, maxIntervalSupplier, multiplierSupplier, setInitialInterval, setMaxInterval, setMultiplier, setSleeper, toString, withSleeper
-
Constructor Details
-
ExponentialRandomBackOffPolicy
public ExponentialRandomBackOffPolicy()
-
-
Method Details
-
start
Returns a new instance ofBackOffContext
, seeded with this policies settings.- Specified by:
start
in interfaceBackOffPolicy
- Overrides:
start
in classExponentialBackOffPolicy
- Parameters:
context
- theRetryContext
context, which might contain information that we can use to decide how to proceed.- Returns:
- the implementation-specific
BackOffContext
or 'null
'.
-
newInstance
- Overrides:
newInstance
in classExponentialBackOffPolicy
-