title: OpenJDK 11's HttpClient causes "Too many files opened" exception when create multiple instances
body: <p>I'm trying to use HttpClient from JDK 11 by following the example from this link <a href="https://openjdk.java.net/groups/net/httpclient/intro.html" rel="nofollow noreferrer">https://openjdk.java.net/groups/net/httpclient/intro.html</a>. My code is simply to call an API multiple times. It looks like following:</p>
  
  <pre><code>for(int x=0; x &lt; 3000; ++x) {
     HttpClient client = HttpClient.newHttpClient();
     HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("http://example.com/"))
        .build();
     client.sendAsync(request, BodyHandlers.ofString())
        .thenApply(HttpResponse::body)
        .thenAccept(System.out::println);
  }
  </code></pre>
  
  <p>This code causes an <code>IOException</code> at <code>HttpClient.newHttpClient()</code> </p>
  
  <pre><code>java.lang.InternalError: java.io.IOException: Too many open files
      at java.net.http/jdk.internal.net.http.HttpClientImpl.&lt;init&gt;(HttpClientImpl.java:311)
      at java.net.http/jdk.internal.net.http.HttpClientImpl.create(HttpClientImpl.java:253)
      at java.net.http/jdk.internal.net.http.HttpClientBuilderImpl.build(HttpClientBuilderImpl.java:135)
      at java.net.http/java.net.http.HttpClient.newHttpClient(HttpClient.java:158)
  ...
  </code></pre>
  
  <p>I'm running it on Ubuntu 18.04.1 with file handle limit = 1024.</p>
  
  <p>I figure out that the problem is solved if I create <code>HttpClient</code> instance once. But I need that <code>HttpClient</code> in many places of my project and I don't want to to make a global variable for it.  Is there a way to create local <code>HttpClient</code> without causing this problem?</p>