title: How would I create parallel HTTP GET requests in Java
body: <p>To begin, I should note that I'm pretty new to Java, so doing research on this topic has quite a learning curve, and I hardly understand what I am reading. My intended goal is to send multiple HTTP GET requests (~60) and then combine all of the data into a JSONObject in a reasonable timeframe.</p>
  <p>I have managed to partially pull off the task (though my methods are likely unorthodox), however, it was synchronous which left me waiting for quite a while before I received my response which is not what I'm aiming to achieve.</p>
  <p>If anyone could provide some insight on how I can approach this, it'll be of great help, as well as where I can learn more about the parts being used.</p>
  <pre class="lang-java prettyprint-override"><code>    private static int pages;
      private static final String BASE = &quot;https://someapi.com/api?page=&quot;;
  
      public static String getData() throws IOException {
          JSONObject finalData = new JSONObject();
  
          System.out.println(&quot;Attempting to get API data!&quot;);
          HttpClient client = HttpClientBuilder.create().build();
          HttpGet request = new HttpGet(
                  BASE + &quot;0&quot;);
          HttpResponse response = client.execute(request);
  
          String result = IOUtils.toString(new BufferedReader
                  (new InputStreamReader(
                          response.getEntity().getContent())));
      
          JSONObject jsonData = new JSONObject(result);
          pages = jsonData.getInt(&quot;totalPages&quot;);
          totalData.put(&quot;0&quot;, jsonData.getJSONArray(&quot;data&quot;));
          for (int x = 1; x &lt; pages; x++) {
              totalData.put(Integer.toString(x), getPageData(x)); // getPageData is essentially a copy-paste of the HTTP client except it has a different number being added to the paste.
          }
          return totalData.toString();
      }
  </code></pre>