title: How to configure the number of allowed pending requests in Apache async client
body: <p>I'm developing an HTTP client application, using Apache httpasyncclient version 4.0.2.</p>
  
  <p>I would like to configure the maximum number of pending requests. Initially I assumed this number is the same as the maximum number of connections. I set this to 20 in the following way:</p>
  
  <pre><code>    final CloseableHttpAsyncClient httpclient;
  </code></pre>
  
  <p>In the constructor:</p>
  
  <pre><code>    final NHttpConnectionFactory&lt;ManagedNHttpClientConnection&gt; connFactory = new ManagedNHttpClientConnectionFactory(new DefaultHttpRequestWriterFactory(), new DefaultHttpResponseParserFactory(), HeapByteBufferAllocator.INSTANCE);
      final IOReactorConfig ioReactorConfig = IOReactorConfig.custom()
              .setIoThreadCount(4)
              .setConnectTimeout(30000)
              .setSoTimeout(30000)
              .build();
      final PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor(ioReactorConfig), connFactory);
      final int maxConns = 20;
      connManager.setDefaultMaxPerRoute(maxConns);
      connManager.setMaxTotal(maxConns);
      httpclient = HttpAsyncClientBuilder.create().setConnectionManager(connManager).build();
      httpclient.start();
  </code></pre>
  
  <p>and later:</p>
  
  <pre><code>    final BasicAsyncRequestProducer requestProducer = new BasicAsyncRequestProducer(URIUtils.extractHost(URI.create(serverAddress)), request) {
          @Override
          public void requestCompleted(HttpContext context) {
              pendings.add(callback);
              logMessage(Direction.REQUEST, req);
              handler.onContentWriteCompleted();
          }
      };
      httpclient.execute(requestProducer, HttpAsyncMethods.createConsumer(), new HttpClientContext(), callback);
  </code></pre>
  
  <p>where callback is where I handle the response.</p>
  
  <p>As a proof of concept it fails. Indeed get do four threads running, but when I try to send 20 messages simultaneously, only 8 are sent immediately, the rest must wait until the server responds to them.</p>
  
  <p>Apache debug messages are indicating that 20 connections have indeed been created. It seems that more configuration must be done.</p>
  
  <p>?</p>