public class ExponentialDelay extends Delay
1 * 2 ^ (attemptNumber-1)
. Actually each step can be based on a
different number than 1 unit of time using the growBy
parameter: growBy * 2 ^ (attemptNumber-1)
.
By default with growBy = 1 this gives us 0 (initial attempt), 1, 2, 4, 8, 16, 32...
Each of the resulting values that is below the lowerBound
will be replaced by the lower bound, and
each value over the upperBound
will be replaced by the upper bound.
For example, given the following Delay.exponential(TimeUnit.MILLISECONDS, 4000, 0, 500)
* the upper of 4000 means the delay will be capped at 4s
* the lower of 0 is useful to allow for immediate execution of original attempt, attempt 0 (if we ever call the
delay with a parameter of 0)
* the growBy of 500 means that we take steps based on 500ms
This yields the following delays: 0ms, 500ms, 1s, 2s, 4s, 4s, 4s,...
In detail : 0, 500 * 2^0, 500 * 2^1, 500 * 2^2, 500 * 2^3, max(4000, 500 * 2^4), max(4000, 500 * 2^5),...
.
Finally, the powers used in the computation can be changed from powers of two by default to another base using the
powersOf parameter.Modifier and Type | Method and Description |
---|---|
long |
calculate(long attempt)
Calculate a specific delay based on the attempt passed in.
|
protected long |
calculateAlternatePower(long attempt) |
protected long |
calculatePowerOfTwo(long attempt) |
String |
toString() |
exponential, exponential, exponential, exponential, exponential, fixed, linear, linear, linear, linear, unit
public long calculate(long attempt)
Delay
protected long calculateAlternatePower(long attempt)
protected long calculatePowerOfTwo(long attempt)
Copyright © 2018 Couchbase, Inc.. All rights reserved.