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.

@UnstableApi @FunctionalInterface public interface ConcurrencyLimit
Limits the concurrency of client requests.
  • Method Details

    • of

      static ConcurrencyLimit of(int maxConcurrency)
      Returns a newly-created ConcurrencyLimit with the specified maxConcurrency.
      Parameters:
      maxConcurrency - the maximum number of concurrent active requests. Specify 0 to disable the limit.
    • builder

      static ConcurrencyLimitBuilder builder(int maxConcurrency)
      Returns a new ConcurrencyLimitBuilder with the specified maxConcurrency.
      Parameters:
      maxConcurrency - the maximum number of concurrent active requests. Specify 0 to disable the limit.
    • acquire

      Acquires a SafeCloseable that allows you to execute a job under the limit. The SafeCloseable 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();
       });