你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
ExponentialBackoff Class
- java.
lang. Object - com.
azure. core. http. policy. ExponentialBackoff
- com.
Implements
public class ExponentialBackoff
implements RetryStrategy
The ExponentialBackoff
class is an implementation of the RetryStrategy interface. This strategy uses a delay duration that exponentially increases with each retry attempt until an upper bound is reached, after which every retry attempt is delayed by the provided max delay duration.
This class is useful when you need to handle retries for operations that may transiently fail. It ensures that the retries are performed with an increasing delay to avoid overloading the system.
Code sample:
In this example, an ExponentialBackoff
is created and used in a RetryPolicy
which can be added to a pipeline. For a request sent by the pipeline, if the server responds with a transient error, the request will be retried with an exponentially increasing delay.
ExponentialBackoff retryStrategy = new ExponentialBackoff();
RetryPolicy policy = new RetryPolicy(retryStrategy);
Constructor Summary
Constructor | Description |
---|---|
ExponentialBackoff() |
Creates an instance of ExponentialBackoff with a maximum number of retry attempts configured by the environment property PROPERTY_AZURE_REQUEST_RETRY_COUNT, or three if it isn't configured or is less than or equal to 0. |
ExponentialBackoff(ExponentialBackoffOptions options) |
Creates an instance of ExponentialBackoff. |
ExponentialBackoff(int maxRetries, Duration baseDelay, Duration maxDelay) |
Creates an instance of ExponentialBackoff. |
Method Summary
Modifier and Type | Method and Description |
---|---|
Duration |
calculateRetryDelay(int retryAttempts)
Computes the delay between each retry. |
int |
getMaxRetries()
Max number of retry attempts to be make. |
boolean |
shouldRetryCondition(RequestRetryCondition requestRetryCondition)
This method is consulted to determine if a retry attempt should be made for the given RequestRetryCondition. |
Methods inherited from java.lang.Object
Constructor Details
ExponentialBackoff
public ExponentialBackoff()
Creates an instance of ExponentialBackoff with a maximum number of retry attempts configured by the environment property PROPERTY_AZURE_REQUEST_RETRY_COUNT, or three if it isn't configured or is less than or equal to 0. This strategy starts with a delay of 800 milliseconds and exponentially increases with each additional retry attempt to a maximum of 8 seconds.
ExponentialBackoff
public ExponentialBackoff(ExponentialBackoffOptions options)
Creates an instance of ExponentialBackoff.
Parameters:
ExponentialBackoff
public ExponentialBackoff(int maxRetries, Duration baseDelay, Duration maxDelay)
Creates an instance of ExponentialBackoff.
Parameters:
Method Details
calculateRetryDelay
public Duration calculateRetryDelay(int retryAttempts)
Computes the delay between each retry.
Parameters:
getMaxRetries
public int getMaxRetries()
Max number of retry attempts to be make.
shouldRetryCondition
public boolean shouldRetryCondition(RequestRetryCondition requestRetryCondition)
This method is consulted to determine if a retry attempt should be made for the given RequestRetryCondition.
By default, if the RequestRetryCondition contains a non-null HttpResponse, then the #shouldRetry(HttpResponse) method is called, otherwise the #shouldRetryException(Throwable) method is called.
Parameters:
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈