public class MaxAttemptsRetryPolicy extends Object implements RetryPolicy
It is not recommended to use it directly, because usually exception classification is strongly recommended (to not retry on OutOfMemoryError, for example).
For daily usage see RetryTemplate.builder()
Volatility of maxAttempts allows concurrent modification and does not require safe publication of new instance after construction.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_ATTEMPTS
The default limit to the number of attempts for a new policy.
|
| Constructor and Description |
|---|
MaxAttemptsRetryPolicy()
Create a
MaxAttemptsRetryPolicy with the default number of retry attempts
(3), retrying all throwables. |
MaxAttemptsRetryPolicy(int maxAttempts)
Create a
MaxAttemptsRetryPolicy with the specified number of retry
attempts, retrying all throwables. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canRetry(RetryContext context)
Test for retryable operation based on the status.
|
void |
close(RetryContext status) |
int |
getMaxAttempts()
The maximum number of attempts before failure.
|
RetryContext |
open(RetryContext parent)
Get a status object that can be used to track the current operation according to
this policy.
|
void |
registerThrowable(RetryContext context,
Throwable throwable)
Update the status with another attempted retry and the latest exception.
|
void |
setMaxAttempts(int maxAttempts)
Set the number of attempts before retries are exhausted.
|
public static final int DEFAULT_MAX_ATTEMPTS
public MaxAttemptsRetryPolicy()
MaxAttemptsRetryPolicy with the default number of retry attempts
(3), retrying all throwables.public MaxAttemptsRetryPolicy(int maxAttempts)
MaxAttemptsRetryPolicy with the specified number of retry
attempts, retrying all throwables.maxAttempts - the maximum number of attemptspublic void setMaxAttempts(int maxAttempts)
>= 1. For example
setting this property to 3 means 3 attempts total (initial + 2 retries).maxAttempts - the maximum number of attempts including the initial attempt.public int getMaxAttempts()
public boolean canRetry(RetryContext context)
canRetry in interface RetryPolicycontext - the current retry statusRetryPolicy.canRetry(RetryContext)public void close(RetryContext status)
close in interface RetryPolicystatus - a retry status created by the RetryPolicy.open(RetryContext) method of
this policy.public void registerThrowable(RetryContext context, Throwable throwable)
registerThrowable in interface RetryPolicycontext - the current status object.throwable - the exception to throwRetryPolicy.registerThrowable(RetryContext, Throwable)public RetryContext open(RetryContext parent)
open in interface RetryPolicyparent - the parent context if we are in a nested retry.RetryContext object specific to this policy.RetryPolicy.open(RetryContext)Copyright © 2022 SpringSource. All rights reserved.