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.

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.

Since:
7.0
Author:
Juergen Hoeller, Hyunsang Han, Sam Brannen
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The concurrency limit.
    The concurrency limit, as a configurable String.
    int
    Alias for limit().
  • Element Details

    • value

      @AliasFor("limit") int value
      Alias for limit().

      Intended to be used when no other attributes are needed — for example, @ConcurrencyLimit(5).

      See Also:
      Default:
      -2147483648
    • limit

      @AliasFor("value") int limit
      The concurrency limit.

      Specify 1 to effectively lock the target instance for each method invocation.

      Specify a limit greater than 1 for pool-like throttling, constraining the number of concurrent invocations similar to the upper bound of a pool.

      Specify -1 for unbounded concurrency.

      See Also:
      Default:
      -2147483648
    • limitString

      String limitString
      The concurrency limit, as a configurable String.

      A non-empty value specified here overrides the limit() and value() attributes.

      This supports Spring-style "${...}" placeholders as well as SpEL expressions.

      See the Javadoc for limit() for details on supported values.

      See Also:
      Default:
      ""