From 4cdfd908829cb615867a5089b5ec67d920e80879 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Sat, 28 Jun 2025 19:14:45 +0200 Subject: [PATCH] Polish backoff and retry support This revises commit 15dd320b95aa404c9542e029588c7aefef5c37ff. See gh-34529 See gh-35110 --- .../org/springframework/aop/retry/MethodRetrySpec.java | 6 +++--- .../springframework/aop/retry/annotation/Retryable.java | 7 ++++--- .../springframework/util/backoff/ExponentialBackOff.java | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/retry/MethodRetrySpec.java b/spring-aop/src/main/java/org/springframework/aop/retry/MethodRetrySpec.java index 76b32330db..6d9e499d21 100644 --- a/spring-aop/src/main/java/org/springframework/aop/retry/MethodRetrySpec.java +++ b/spring-aop/src/main/java/org/springframework/aop/retry/MethodRetrySpec.java @@ -31,10 +31,10 @@ import java.util.Collections; * @param excludes non-applicable exception types to avoid a retry for * @param predicate a predicate for filtering exceptions from applicable methods * @param maxAttempts the maximum number of retry attempts - * @param delay the base delay after the initial invocation (in milliseconds) - * @param jitter a jitter value for the next retry attempt (in milliseconds) + * @param delay the base delay after the initial invocation + * @param jitter a jitter value for the next retry attempt * @param multiplier a multiplier for a delay for the next retry attempt - * @param maxDelay the maximum delay for any retry attempt (in milliseconds) + * @param maxDelay the maximum delay for any retry attempt * @see AbstractRetryInterceptor#getRetrySpec * @see SimpleRetryInterceptor#SimpleRetryInterceptor(MethodRetrySpec) * @see org.springframework.aop.retry.annotation.Retryable diff --git a/spring-aop/src/main/java/org/springframework/aop/retry/annotation/Retryable.java b/spring-aop/src/main/java/org/springframework/aop/retry/annotation/Retryable.java index 4868b45722..f0be61bbb1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/retry/annotation/Retryable.java +++ b/spring-aop/src/main/java/org/springframework/aop/retry/annotation/Retryable.java @@ -43,6 +43,7 @@ import org.springframework.core.annotation.AliasFor; * @since 7.0 * @see RetryAnnotationBeanPostProcessor * @see RetryAnnotationInterceptor + * @see org.springframework.core.retry.RetryPolicy * @see org.springframework.core.retry.RetryTemplate * @see reactor.core.publisher.Mono#retryWhen * @see reactor.core.publisher.Flux#retryWhen @@ -95,8 +96,8 @@ public @interface Retryable { long maxAttempts() default 3; /** - * The base delay after the initial invocation in milliseconds. If a multiplier - * is specified, this serves as the initial delay to multiply from. + * The base delay after the initial invocation. If a multiplier is specified, + * this serves as the initial delay to multiply from. *

The time unit is milliseconds by default but can be overridden via * {@link #timeUnit}. *

The default is 1000. @@ -147,7 +148,7 @@ public @interface Retryable { /** * The {@link TimeUnit} to use for {@link #delay}, {@link #jitter}, * and {@link #maxDelay}. - *

Defaults to {@link TimeUnit#MILLISECONDS}. + *

The default is {@link TimeUnit#MILLISECONDS}. */ TimeUnit timeUnit() default TimeUnit.MILLISECONDS; diff --git a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java index 0236497bcb..c641f2887e 100644 --- a/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java +++ b/spring-core/src/main/java/org/springframework/util/backoff/ExponentialBackOff.java @@ -90,7 +90,7 @@ public class ExponentialBackOff implements BackOff { * The default maximum attempts: unlimited. * @since 6.1 */ - public static final int DEFAULT_MAX_ATTEMPTS = Integer.MAX_VALUE; + public static final long DEFAULT_MAX_ATTEMPTS = Long.MAX_VALUE; private long initialInterval = DEFAULT_INITIAL_INTERVAL;