Class ExponentialBackOff
- All Implemented Interfaces:
BackOff
nextBackOffMillis() is calculated using the following formula:
randomized_interval = retry_interval * (random value in range [1 - randomization_factor, 1 + randomization_factor])
In other words nextBackOffMillis() will range between the randomization factor
percentage below and above the retry interval. For example, using 2 seconds as the base retry
interval and 0.5 as the randomization factor, the actual back off period used in the next retry
attempt will be between 1 and 3 seconds.
Note: max_interval caps the retry_interval and not the randomized_interval.
Example: The default retry_interval is .5 seconds, default randomization_factor is 0.5, default multiplier is 1.5 and the default max_interval is 1 minute. For 10 tries the sequence will be (values in seconds) and assuming we go over the max_elapsed_time on the 10th try:
request# retry_interval randomized_interval
1 0.5 [0.25, 0.75]
2 0.75 [0.375, 1.125]
3 1.125 [0.562, 1.687]
4 1.687 [0.8435, 2.53]
5 2.53 [1.265, 3.795]
6 3.795 [1.897, 5.692]
7 5.692 [2.846, 8.538]
8 8.538 [4.269, 12.807]
9 12.807 [6.403, 19.210]
10 19.210 maxElapsedTimeMillis
Implementation is not thread-safe.
- Since:
- 1.15
- Author:
- Ravi Mistry
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionlongvoidreset()Sets the interval back to the initial retry interval and restarts the timer.
-
Method Details
-
reset
public void reset()Sets the interval back to the initial retry interval and restarts the timer. -
nextBackOffMillis
public long nextBackOffMillis()This method calculates the next back off interval using the formula: randomized_interval = retry_interval +/- (randomization_factor * retry_interval)
Subclasses may override if a different algorithm is required.
- Specified by:
nextBackOffMillisin interfaceBackOff
-