guava-retrying
guava-retrying copied to clipboard
Initial wait time in an exponential retry strategy.
Is there a way to initialize the wait strategy to be a fixed amount of time? As in, all successive exponential wait times are added onto a fixed wait time. For example, the computeSleepTime
for the exponential wait strategy which is currently
@Override
public long computeSleepTime(Attempt failedAttempt) {
double exp = Math.pow(2, failedAttempt.getAttemptNumber());
long result = Math.round(multiplier * exp);
if (result > maximumWait) {
result = maximumWait;
}
return result >= 0L ? result : 0L;
}
can return something like initialWait + (result >= 0L ? result : 0L)
?
Perhaps this can already be accomplished in another way?
I think the closest option is this method in WaitStrategies:
public static WaitStrategy exponentialWait(long multiplier,
long maximumTime,
@Nonnull TimeUnit maximumTimeUnit)
The exponential wait is normally in milliseconds. If you know your operation typically takes, say, 800 ms, then you would do something like this:
WaitStrategy = exponentialWait(1000, 5, TimeUnit.MINUTES);
That way your waits would be in seconds instead of milliseconds.
Ah, interesting. Upon digging, I'm assuming it would also suffice to use the CompositeWaitStrategy
as well, with a ExponentialWaitStrategy
and FixedWaitStrategy
.
It is inconvenient. It is logical to use fixed start time and maximum time. For example, when I have a disconnection issue I want to retry after 5 seconds and exponentially increase every next attempt. Why do I need to calculate time to wait?