Top Description Inners Fields Constructors Methods
org.springframework.util.backoff

public Class ExponentialBackOff

extends Object
implements BackOff
Class Inheritance
All Implemented Interfaces
org.springframework.util.backoff.BackOff
Imports
java.util.StringJoiner, org.springframework.util.Assert

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 2000 ms; the default multiplier is 1.5; and the default max interval is 30000. 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, and the default maximum number of attempts is Integer#MAX_VALUE. Use setMaxElapsedTime to limit the length of time that an instance should accumulate before returning BackOffExecution#STOP. Alternatively, use setMaxAttempts to limit the number of attempts. The execution stops when either of those two limits is reached.

Authors
Stephane Nicoll, Gary Russell
Since
4.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
public static final long
DEFAULT_INITIAL_INTERVAL

The default initial interval.

public static final int
DEFAULT_MAX_ATTEMPTS

The default maximum attempts.

public static final long
DEFAULT_MAX_ELAPSED_TIME

The default maximum elapsed time.

public static final long
DEFAULT_MAX_INTERVAL

The default maximum back off time.

public static final double
DEFAULT_MULTIPLIER

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

private long
private int
private long
private long
private double

Constructor Summary

AccessConstructor and Description
public
ExponentialBackOff()

Create an instance with the default settings.

public
ExponentialBackOff(long
the initial interval in milliseconds
initialInterval
,
double
the multiplier (should be greater than or equal to 1)
multiplier
)

Create an instance with the supplied settings.

Method Summary

Modifier and TypeMethod and Description
private void
checkMultiplier(double multiplier)

public long
getInitialInterval()

Return the initial interval in milliseconds.

public int

Returns:

the maximum number of attempts
getMaxAttempts
()

Return the maximum number of attempts after which a call to BackOffExecution#nextBackOff() returns BackOffExecution#STOP.

public long

Returns:

the maximum elapsed time
getMaxElapsedTime
()

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

public long
getMaxInterval()

Return the maximum back off time in milliseconds.

public double
getMultiplier()

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

public void
setInitialInterval(long initialInterval)

Set the initial interval in milliseconds.

public void
setMaxAttempts(int
the maximum number of attempts
maxAttempts
)

The maximum number of attempts after which a call to BackOffExecution#nextBackOff() returns BackOffExecution#STOP.

public void
setMaxElapsedTime(long
the maximum elapsed time
maxElapsedTime
)

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

public void
setMaxInterval(long maxInterval)

Set the maximum back off time in milliseconds.

public void
setMultiplier(double multiplier)

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

public BackOffExecution
start()

Implements org.springframework.util.backoff.BackOff.start.

Start a new back off execution.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_INITIAL_INTERVALback to summary
public static final long DEFAULT_INITIAL_INTERVAL

The default initial interval.

DEFAULT_MAX_ATTEMPTSback to summary
public static final int DEFAULT_MAX_ATTEMPTS

The default maximum attempts.

Since
6.1
DEFAULT_MAX_ELAPSED_TIMEback to summary
public static final long DEFAULT_MAX_ELAPSED_TIME

The default maximum elapsed time.

DEFAULT_MAX_INTERVALback to summary
public static final long DEFAULT_MAX_INTERVAL

The default maximum back off time.

DEFAULT_MULTIPLIERback to summary
public static final double DEFAULT_MULTIPLIER

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

initialIntervalback to summary
private long initialInterval
maxAttemptsback to summary
private int maxAttempts
maxElapsedTimeback to summary
private long maxElapsedTime
maxIntervalback to summary
private long maxInterval
multiplierback to summary
private double multiplier

Constructor Detail

ExponentialBackOffback to summary
public ExponentialBackOff()

Create an instance with the default settings.

See Also
DEFAULT_INITIAL_INTERVAL, DEFAULT_MULTIPLIER, DEFAULT_MAX_INTERVAL, DEFAULT_MAX_ELAPSED_TIME, DEFAULT_MAX_ATTEMPTS
ExponentialBackOffback to summary
public ExponentialBackOff(long initialInterval, double multiplier)

Create an instance with the supplied settings.

Parameters
initialInterval:long

the initial interval in milliseconds

multiplier:double

the multiplier (should be greater than or equal to 1)

Method Detail

checkMultiplierback to summary
private void checkMultiplier(double multiplier)
getInitialIntervalback to summary
public long getInitialInterval()

Return the initial interval in milliseconds.

getMaxAttemptsback to summary
public int getMaxAttempts()

Return the maximum number of attempts after which a call to BackOffExecution#nextBackOff() returns BackOffExecution#STOP.

Returns:int

the maximum number of attempts

Since
6.1
See Also
getMaxElapsedTime()
getMaxElapsedTimeback to summary
public long getMaxElapsedTime()

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

Returns:long

the maximum elapsed time

See Also
getMaxAttempts()
getMaxIntervalback to summary
public long getMaxInterval()

Return the maximum back off time in milliseconds.

getMultiplierback to summary
public double getMultiplier()

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

setInitialIntervalback to summary
public void setInitialInterval(long initialInterval)

Set the initial interval in milliseconds.

setMaxAttemptsback to summary
public void setMaxAttempts(int maxAttempts)

The maximum number of attempts after which a call to BackOffExecution#nextBackOff() returns BackOffExecution#STOP.

Parameters
maxAttempts:int

the maximum number of attempts

Since
6.1
See Also
setMaxElapsedTime
setMaxElapsedTimeback to summary
public void setMaxElapsedTime(long maxElapsedTime)

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

Parameters
maxElapsedTime:long

the maximum elapsed time

See Also
setMaxAttempts
setMaxIntervalback to summary
public void setMaxInterval(long maxInterval)

Set the maximum back off time in milliseconds.

setMultiplierback to summary
public void setMultiplier(double multiplier)

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

startback to summary
public BackOffExecution start()

Implements org.springframework.util.backoff.BackOff.start.

Doc from org.springframework.util.backoff.BackOff.start.

Start a new back off execution.

Returns:BackOffExecution

a fresh BackOffExecution ready to be used

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.springframework.util.backoff back to summary

private Class ExponentialBackOff.ExponentialBackOffExecution

extends Object
implements BackOffExecution
Class Inheritance
  • java.lang.Object
  • org.springframework.util.backoff.ExponentialBackOff.ExponentialBackOffExecution
All Implemented Interfaces
org.springframework.util.backoff.BackOffExecution

Field Summary

Modifier and TypeField and Description
private int
private long
private long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private long
private long
multiplyInterval(long maxInterval)

public long
nextBackOff()

Implements org.springframework.util.backoff.BackOffExecution.nextBackOff.

Return the number of milliseconds to wait before retrying the operation or STOP (-1) to indicate that no further attempt should be made for the operation.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

attemptsback to summary
private int attempts
currentElapsedTimeback to summary
private long currentElapsedTime
currentIntervalback to summary
private long currentInterval

Constructor Detail

ExponentialBackOffExecutionback to summary
private ExponentialBackOffExecution()

Method Detail

computeNextIntervalback to summary
private long computeNextInterval()
multiplyIntervalback to summary
private long multiplyInterval(long maxInterval)
nextBackOffback to summary
public long nextBackOff()

Implements org.springframework.util.backoff.BackOffExecution.nextBackOff.

Doc from org.springframework.util.backoff.BackOffExecution.nextBackOff.

Return the number of milliseconds to wait before retrying the operation or STOP (-1) to indicate that no further attempt should be made for the operation.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override