public class BackoffThrottler extends Object
min(pow(backoffCoefficient, failureCount - 1) * initialSleep, maxSleep);
Example usage:
BackoffThrottler throttler = new BackoffThrottler(1000, 60000, 2);
while(!stopped) {
try {
throttler.throttle();
// some code that can fail and should be throttled
...
throttler.success();
}
catch (Exception e) {
throttler.failure();
}
}
| Constructor and Description |
|---|
BackoffThrottler(long initialSleep,
long maxSleep,
double backoffCoefficient)
Construct an instance of the throttler.
|
public BackoffThrottler(long initialSleep,
long maxSleep,
double backoffCoefficient)
initialSleep - time to sleep on the first failuremaxSleep - maximum time to sleep independently of number of failuresbackoffCoefficient - coefficient used to calculate the next time to sleep.public void throttle()
throws InterruptedException
InterruptedExceptionpublic void success()
public void failure()
Copyright © 2013 Amazon Web Services, Inc. All Rights Reserved.