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
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The applicable concurrency limit: 1 by default, effectively locking the target instance for each method invocation.
  • Element Details

    • value

      int value
      The applicable concurrency limit: 1 by default, effectively locking the target instance for each method invocation.

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

      Default:
      1