How to Limit Concurrency
It is possible to prevent an operation from having too many concurrent executions using a bulkhead.
In general, the term bulkhead refers to system compartmentalization, or the practice of preventing failures in one part of the system from spreading to other parts of the system. In MicroProfile Fault Tolerance, the term refers to one specific instance of the general idea: a concurrency limiter. |
@Bulkhead
The @Bulkhead
annotation specifies that a concurrency limit should be enforced for all calls of the method.
@ApplicationScoped
public class MyService {
@Bulkhead (1)
public String hello() {
...
}
}
1 | Declares that hello() must not have too many concurrent executions.
Since there is no configuration, the default is at most 10 concurrent calls. |
If some callers attempt to invoke the method when the concurrency limit has already been reached, they will fail with BulkheadException
.
It is possible to specify the maximum allowed concurrency, as well as define a queue for excess invocations in case of asynchronous methods.
Links
For more information, see the Bulkhead reference guide.