Interface ConcurrencyLimit
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Limits the concurrency of client requests.
-
Method Summary
Modifier and TypeMethodDescriptionacquire(ClientRequestContext ctx)
Acquires aSafeCloseable
that allows you to execute a job under the limit.static ConcurrencyLimitBuilder
builder(int maxConcurrency)
Returns a newConcurrencyLimitBuilder
with the specifiedmaxConcurrency
.static ConcurrencyLimit
of(int maxConcurrency)
Returns a newly-createdConcurrencyLimit
with the specifiedmaxConcurrency
.
-
Method Details
-
of
Returns a newly-createdConcurrencyLimit
with the specifiedmaxConcurrency
.- Parameters:
maxConcurrency
- the maximum number of concurrent active requests. Specify0
to disable the limit.
-
builder
Returns a newConcurrencyLimitBuilder
with the specifiedmaxConcurrency
.- Parameters:
maxConcurrency
- the maximum number of concurrent active requests. Specify0
to disable the limit.
-
acquire
Acquires aSafeCloseable
that allows you to execute a job under the limit. TheSafeCloseable
must be closed after the job is done:ConcurrencyLimit limit = ... limit.acquire(ctx).handle((permit, cause) -> { if (cause != null) { // Failed to acquire a permit. ... } // Execute your job. ... // Release the permit. permit.close(); });
-