Annotation Interface ConcurrencyLimit
policy() as policy = REJECT.
In the type-level case, all methods inheriting the concurrency limit from the type level share a common concurrency throttle, with any mix of such method invocations contributing to the shared concurrency limit. Whereas for a locally annotated method, a local throttle with the specified limit is going to be applied to invocations of that particular method only.
This is particularly useful with Virtual Threads where there is generally
no thread pool limit in place. For asynchronous tasks, this can be constrained
on SimpleAsyncTaskExecutor. For
synchronous invocations, this annotation provides equivalent behavior through
ConcurrencyThrottleInterceptor.
Alternatively, consider SyncTaskExecutor
and its inherited concurrency throttling support (new as of 7.0) for
programmatic use.
- Since:
- 7.0
- Author:
- Juergen Hoeller, Hyunsang Han, Sam Brannen
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumPolicy to apply for throttling method invocations when the limit has been reached. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionintThe concurrency limit.The concurrency limit, as a configurable String.The policy for throttling method invocations when the limit has been reached.intAlias forlimit().
-
Element Details
-
value
-
limit
The concurrency limit.Specify
1to effectively lock the target instance for each method invocation.Specify a limit greater than
1for pool-like throttling, constraining the number of concurrent invocations similar to the upper bound of a pool.Specify
-1for unbounded concurrency.- See Also:
- Default:
-2147483648
-
limitString
String limitStringThe concurrency limit, as a configurable String.A non-empty value specified here overrides the
limit()andvalue()attributes.This supports Spring-style "${...}" placeholders as well as SpEL expressions.
See the Javadoc for
limit()for details on supported values.- See Also:
- Default:
""
-
policy
The policy for throttling method invocations when the limit has been reached.The default behavior is to block further concurrent invocations once the specified limit has been reached:
ConcurrencyLimit.ThrottlePolicy.BLOCK.Switch this policy to
REJECTfor rejecting further invocations instead, throwingInvocationRejectedException(which extends the commonRejectedExecutionException) on any further concurrent invocation attempts:ConcurrencyLimit.ThrottlePolicy.REJECT.- Since:
- 7.0.3
- Default:
BLOCK
-