title: Java 11 HttpClient - What is Optimum Ratio of HttpClients to Concurrent HttpRequests
body: <p>In the example below I create one Java 11 httpClient and then create multiple concurrent HttpRequests.</p>
  <ol>
  <li>Is this bad practice?</li>
  <li>Should each HttpRequest have its own HttpClient?</li>
  <li>Is there an upper limit on the number of HttpRequests a HttpClient can have?</li>
  </ol>
  <p><strong>Code</strong></p>
  <pre><code>    private static void httpClientExample(){
      
      HttpClient httpClient = HttpClient.newHttpClient();
  
      System.out.println(&quot;TP1&quot;);
  
      var task1 = httpClient.sendAsync(HttpRequest.newBuilder()
              .uri(URI.create(&quot;https://www.bing.com/&quot;))
              .build(), HttpResponse.BodyHandlers.ofString())
              .thenApply(HttpResponse::uri).thenAccept(System.out::println);
  
      var task2 = httpClient.sendAsync(HttpRequest.newBuilder()
              .uri(URI.create(&quot;https://openjdk.java.net/&quot;))
              .build(), HttpResponse.BodyHandlers.ofString())
              .thenApply(HttpResponse::uri).thenAccept(System.out::println);
      
      var task3 = httpClient.sendAsync(HttpRequest.newBuilder()
              .uri(URI.create(&quot;https://www.google.co.uk/&quot;))
              .build(), HttpResponse.BodyHandlers.ofString())
              .thenApply(HttpResponse::uri).thenAccept(System.out::println);
  
  
      System.out.println(&quot;Requests Sent&quot;);
  
      try {
          Thread.sleep(5000);
      } catch (InterruptedException e) {
          e.printStackTrace();
      }
  
      System.out.println(&quot;Main Thread Completed&quot;);
      }
  </code></pre>