Package org.springframework.util.backoff
Class ExponentialBackOff
java.lang.Object
org.springframework.util.backoff.ExponentialBackOff
- All Implemented Interfaces:
- 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 2000L ms; the default multiplier is 1.5; and the default max interval is 30000L. 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(long) to limit the length of time that an instance
 should accumulate before returning BackOffExecution.STOP. Alternatively,
 use setMaxAttempts(int) to limit the number of attempts. The execution
 stops when either of those two limits is reached.
- Since:
- 4.1
- Author:
- Stephane Nicoll, Gary Russell
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final longThe default initial interval.static final intThe default maximum attempts.static final longThe default maximum elapsed time.static final longThe default maximum back off time.static final doubleThe default multiplier (increases the interval by 50%).
- 
Constructor SummaryConstructorsConstructorDescriptionCreate an instance with the default settings.ExponentialBackOff(long initialInterval, double multiplier) Create an instance with the supplied settings.
- 
Method SummaryModifier and TypeMethodDescriptionlongReturn the initial interval in milliseconds.intReturn the maximum number of attempts after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.longReturn the maximum elapsed time in milliseconds after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.longReturn the maximum back off time in milliseconds.doubleReturn the value to multiply the current interval by for each retry attempt.voidsetInitialInterval(long initialInterval) Set the initial interval in milliseconds.voidsetMaxAttempts(int maxAttempts) The maximum number of attempts after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.voidsetMaxElapsedTime(long maxElapsedTime) Set the maximum elapsed time in milliseconds after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.voidsetMaxInterval(long maxInterval) Set the maximum back off time in milliseconds.voidsetMultiplier(double multiplier) Set the value to multiply the current interval by for each retry attempt.start()Start a new back off execution.
- 
Field Details- 
DEFAULT_INITIAL_INTERVALpublic static final long DEFAULT_INITIAL_INTERVALThe default initial interval.- See Also:
 
- 
DEFAULT_MULTIPLIERpublic static final double DEFAULT_MULTIPLIERThe default multiplier (increases the interval by 50%).- See Also:
 
- 
DEFAULT_MAX_INTERVALpublic static final long DEFAULT_MAX_INTERVALThe default maximum back off time.- See Also:
 
- 
DEFAULT_MAX_ELAPSED_TIMEpublic static final long DEFAULT_MAX_ELAPSED_TIMEThe default maximum elapsed time.- See Also:
 
- 
DEFAULT_MAX_ATTEMPTSpublic static final int DEFAULT_MAX_ATTEMPTSThe default maximum attempts.- Since:
- 6.1
- See Also:
 
 
- 
- 
Constructor Details- 
ExponentialBackOffpublic ExponentialBackOff()Create an instance with the default settings.
- 
ExponentialBackOffpublic ExponentialBackOff(long initialInterval, double multiplier) Create an instance with the supplied settings.- Parameters:
- initialInterval- the initial interval in milliseconds
- multiplier- the multiplier (should be greater than or equal to 1)
 
 
- 
- 
Method Details- 
setInitialIntervalpublic void setInitialInterval(long initialInterval) Set the initial interval in milliseconds.
- 
getInitialIntervalpublic long getInitialInterval()Return the initial interval in milliseconds.
- 
setMultiplierpublic void setMultiplier(double multiplier) Set the value to multiply the current interval by for each retry attempt.
- 
getMultiplierpublic double getMultiplier()Return the value to multiply the current interval by for each retry attempt.
- 
setMaxIntervalpublic void setMaxInterval(long maxInterval) Set the maximum back off time in milliseconds.
- 
getMaxIntervalpublic long getMaxInterval()Return the maximum back off time in milliseconds.
- 
setMaxElapsedTimepublic void setMaxElapsedTime(long maxElapsedTime) Set the maximum elapsed time in milliseconds after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.- Parameters:
- maxElapsedTime- the maximum elapsed time
- See Also:
 
- 
getMaxElapsedTimepublic long getMaxElapsedTime()Return the maximum elapsed time in milliseconds after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.- Returns:
- the maximum elapsed time
- See Also:
 
- 
setMaxAttemptspublic void setMaxAttempts(int maxAttempts) The maximum number of attempts after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.- Parameters:
- maxAttempts- the maximum number of attempts
- Since:
- 6.1
- See Also:
 
- 
getMaxAttemptspublic int getMaxAttempts()Return the maximum number of attempts after which a call toBackOffExecution.nextBackOff()returnsBackOffExecution.STOP.- Returns:
- the maximum number of attempts
- Since:
- 6.1
- See Also:
 
- 
startDescription copied from interface:BackOffStart a new back off execution.- Specified by:
- startin interface- BackOff
- Returns:
- a fresh BackOffExecutionready to be used
 
 
-