spring-framework / org.springframework.util.backoff / ExponentialBackOff

ExponentialBackOff

open class ExponentialBackOff : BackOff

Implementation of BackOff that increases the back off period for each retry attempt. When the interval has reached the max interval, it is no longer increased. Stops retrying once the max elapsed time has been reached.

Example: The default interval is {@value #DEFAULT_INITIAL_INTERVAL} ms, the default multiplier is {@value #DEFAULT_MULTIPLIER}, and the default max interval is {@value #DEFAULT_MAX_INTERVAL}. For 10 attempts the sequence will be as follows:

 request# back off 1 2000 2 3000 3 4500 4 6750 5 10125 6 15187 7 22780 8 30000 9 30000 10 30000 

Note that the default max elapsed time is Long#MAX_VALUE. Use #setMaxElapsedTime(long) to limit the maximum length of time that an instance should accumulate before returning BackOffExecution#STOP.

Author
Stephane Nicoll

Since
4.1

Constructors

<init>

ExponentialBackOff()

Create an instance with the default settings.

ExponentialBackOff(initialInterval: Long, multiplier: Double)

Create an instance with the supplied settings.

Properties

DEFAULT_INITIAL_INTERVAL

static val DEFAULT_INITIAL_INTERVAL: Long

The default initial interval.

DEFAULT_MAX_ELAPSED_TIME

static val DEFAULT_MAX_ELAPSED_TIME: Long

The default maximum elapsed time.

DEFAULT_MAX_INTERVAL

static val DEFAULT_MAX_INTERVAL: Long

The default maximum back off time.

DEFAULT_MULTIPLIER

static val DEFAULT_MULTIPLIER: Double

The default multiplier (increases the interval by 50%).

Functions

getInitialInterval

open fun getInitialInterval(): Long

Return the initial interval in milliseconds.

getMaxElapsedTime

open fun getMaxElapsedTime(): Long

Return the maximum elapsed time in milliseconds after which a call to BackOffExecution#nextBackOff() returns BackOffExecution#STOP.

getMaxInterval

open fun getMaxInterval(): Long

Return the maximum back off time.

getMultiplier

open fun getMultiplier(): Double

Return the value to multiply the current interval by for each retry attempt.

setInitialInterval

open fun setInitialInterval(initialInterval: Long): Unit

The initial interval in milliseconds.

setMaxElapsedTime

open fun setMaxElapsedTime(maxElapsedTime: Long): Unit

The maximum elapsed time in milliseconds after which a call to BackOffExecution#nextBackOff() returns BackOffExecution#STOP.

setMaxInterval

open fun setMaxInterval(maxInterval: Long): Unit

The maximum back off time.

setMultiplier

open fun setMultiplier(multiplier: Double): Unit

The value to multiply the current interval by for each retry attempt.

start

open fun start(): BackOffExecution