title: Java 11 HTTP client asynchronous execution
body: <p>I'm trying the new HTTP client API from JDK 11, specifically its asynchronous way of executing requests. But there is something that I'm not sure I understand (sort of an implementation aspect). In the <a href="http://cr.openjdk.java.net/~chegar/httpclient/02/javadoc/api/java.net.http/java/net/http/package-summary.html" rel="noreferrer">documentation</a>, it says:</p>
  
  <blockquote>
    <p>Asynchronous tasks and dependent actions of returned <code>CompletableFuture</code> instances are executed on the threads supplied by the client's <code>Executor</code>, where practical.</p>
  </blockquote>
  
  <p>As I understand this, it means that if I set a custom executor when creating the <code>HttpClient</code> object:</p>
  
  <pre><code>ExecutorService executor = Executors.newFixedThreadPool(3);
  
  HttpClient httpClient = HttpClient.newBuilder()
                        .executor(executor)  // custom executor
                        .build();
  </code></pre>
  
  <p>then if I send a request asynchronously and add dependent actions on the returned <code>CompletableFuture</code>, the dependent action should execute on the specified executor.</p>
  
  <pre><code>httpClient.sendAsync(request, BodyHandlers.ofString())
            .thenAccept(response -&gt; {
        System.out.println("Thread is: " + Thread.currentThread().getName());
        // do something when the response is received
  });
  </code></pre>
  
  <p>However, in the dependent action above (the consumer in <code>thenAccept</code>), I see that the thread doing it is from the common pool and not the custom executor, since it prints <code>Thread is: ForkJoinPool.commonPool-worker-5</code>.</p>
  
  <p>Is this a bug in the implementation? Or something I'm missing? I notice it says "instances are executed on the threads supplied by the client's Executor, <strong>where practical</strong>", so is this a case where this is not applied?</p>
  
  <p>Note that I also tried <code>thenAcceptAsync</code> as well and it's the same result.</p>