Annotation Interface ConcurrencyLimit


@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented @Reflective public @interface ConcurrencyLimit
A common annotation specifying a concurrency limit for an individual method, or for all proxy-invoked methods in a given class hierarchy if annotated at the type level. The default behavior is to block further method invocations when the limit has been reached. Alternatively, further invocations can be rejected through configuring 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 Classes
    Modifier and Type
    Class
    Description
    static enum 
    Policy to apply for throttling method invocations when the limit has been reached.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The concurrency limit.
    The concurrency limit, as a configurable String.
    The policy for throttling method invocations when the limit has been reached.
    int
    Alias for limit().