@@ -8,7 +8,7 @@ in particular `@Retryable` and `@ConcurrencyLimit` annotations for method invoca
8
8
[[resilience-retryable]]
9
9
== Using `@Retryable`
10
10
11
- `@Retryable` is a common annotation specifying retry characteristics for an individual
11
+ `@Retryable` is a common annotation that specifies retry characteristics for an individual
12
12
method (with the annotation declared at the method level), or for all proxy-invoked
13
13
methods in a given class hierarchy (with the annotation declared at the type level).
14
14
@@ -21,10 +21,10 @@ public void sendNotification() {
21
21
----
22
22
23
23
By default, the method invocation will be retried for any exception thrown: with at
24
- most 3 retry attempts after an initial failure, and a delay of 1 second in- between.
24
+ most 3 retry attempts after an initial failure, and a delay of 1 second between attempts .
25
25
26
- This can be specifically adapted for every method if necessary, for example narrowing
27
- the exceptions to retry::
26
+ This can be specifically adapted for every method if necessary – for example, by narrowing
27
+ the exceptions to retry:
28
28
29
29
[source,java,indent=0,subs="verbatim,quotes"]
30
30
----
@@ -51,20 +51,23 @@ return type, decorating the pipeline with Reactor's retry capabilities:
51
51
----
52
52
@Retryable(maxAttempts = 5, delay = 100, jitter = 10, multiplier = 2, maxDelay = 1000)
53
53
public Mono<Void> sendNotification() {
54
- return Mono.from(...); // this raw Mono will get decorated with a retry spec
54
+ return Mono.from(...); // <1>
55
55
}
56
56
----
57
-
57
+ <1> This raw `Mono` will get decorated with a retry spec.
58
+
58
59
For details on the various characteristics, see the available annotation attributes
59
- on {spring-framework-api}/resilience/annotation/Retryable.html[`@Retryable`]. Note:
60
- There a String variants with placeholder support available for several attributes
61
- as well, as an alternative to the specifically typed annotation attributes above.
60
+ in {spring-framework-api}/resilience/annotation/Retryable.html[`@Retryable`].
61
+
62
+ NOTE: There a `String` variants with placeholder support available for several attributes
63
+ as well, as an alternative to the specifically typed annotation attributes used in the
64
+ above examples.
62
65
63
66
64
67
[[resilience-concurrency]]
65
68
== Using `@ConcurrencyLimit`
66
69
67
- `@ConcurrencyLimit` is an annotation specifying a concurrency limit for an individual
70
+ `@ConcurrencyLimit` is an annotation that specifies a concurrency limit for an individual
68
71
method (with the annotation declared at the method level), or for all proxy-invoked
69
72
methods in a given class hierarchy (with the annotation declared at the type level).
70
73
@@ -76,35 +79,37 @@ public void sendNotification() {
76
79
}
77
80
----
78
81
79
- This is meant to protect the target resource from being accessed from too many
80
- threads at the same time, similar to the effect of a pool size limit in case of
81
- thread pool or of a connection pool that blocks access if its limit is reached.
82
+ This is meant to protect the target resource from being accessed from too many threads at
83
+ the same time, similar to the effect of a pool size limit for a thread pool or a
84
+ connection pool that blocks access if its limit is reached.
82
85
83
- At its most constrained, you may set the limit to 1, effectively locking access
84
- to the target bean instance:
86
+ You may optionally set the limit to 1, effectively locking access to the target bean
87
+ instance:
85
88
86
89
[source,java,indent=0,subs="verbatim,quotes"]
87
90
----
88
- @ConcurrencyLimit(1) // 1 is the default but this makes it more readable
91
+ @ConcurrencyLimit(1) // <1>
89
92
public void sendNotification() {
90
93
this.jmsClient.destination("notifications").send(...);
91
94
}
92
95
----
93
-
96
+ <1> 1 is the default, but specifying it makes the intent clearer.
97
+
94
98
Such limiting is particularly useful with Virtual Threads where there is generally
95
99
no thread pool limit in place. For asynchronous tasks, this can be constrained on
96
100
{spring-framework-api}/core/task/SimpleAsyncTaskExecutor.html[`SimpleAsyncTaskExecutor`].
97
101
For synchronous invocations, this annotation provides equivalent behavior through
98
102
{spring-framework-api}/aop/interceptor/ConcurrencyThrottleInterceptor.html[`ConcurrencyThrottleInterceptor`]
99
- which is available since Spring Framework 1.0 for programmatic use with the AOP framework.
103
+ which has been available since Spring Framework 1.0 for programmatic use with the AOP
104
+ framework.
100
105
101
106
102
107
[[resilience-enable]]
103
108
== Configuring `@EnableResilientMethods`
104
109
105
110
Note that like many of Spring's core annotation-based features, `@Retryable` and
106
111
`@ConcurrencyLimit` are designed as metadata that you can choose to honor or ignore.
107
- The most convenient way of enabling actual processing of the resilience annotations
112
+ The most convenient way to enable actual processing of the resilience annotations
108
113
through AOP interception is to declare `@EnableResilientMethods` on a corresponding
109
114
configuration class. Alternatively, you may declare `RetryAnnotationBeanPostProcessor`
110
115
and/or `ConcurrencyLimitBeanPostProcessor` individually.
0 commit comments