title: VertX HTTP request parallel processing
body: <p>I'm using the Java VertX framework and I'm trying to load multiple JSON objects using the VertX WebClient and a simple HTTP request. I want to do this in parallel so it speeds up the process.</p>
  
  <p>I have an Endpoint object:</p>
  
  <pre><code>import io.vertx.core.Vertx;
  import io.vertx.core.json.JsonObject;
  import io.vertx.ext.web.client.WebClient;
  import io.vertx.ext.web.codec.BodyCodec;
  
  public final class Endpoint {
  
      private final String name;
      private final String url;
  
      public Endpoint (String name, String url) {
          this.name = name;
          this.url = url;
      }
  
      public String getName() {
          return name;
      }
  
      public String getUrl() {
          return url;
      }
  
      public JsonObject loadJsonObject() {
          WebClient client = WebClient.create(Vertx.vertx());
          client.getAbs(this.getUrl()).as(BodyCodec.jsonObject()).send(handler -&gt; {
              // what to do
          });
          return null;
      }
  
  }
  </code></pre>
  
  <p>In another class I have the following function that should handle this in parallel (<a href="http://fahdshariff.blogspot.nl/2016/06/java-8-completablefuture-vs-parallel.html" rel="nofollow noreferrer">source</a>):</p>
  
  <pre><code>public static void useCompletableFutureWithExecutor(List&lt;Endpoint&gt; tasks) {
      long start = System.nanoTime();
      ExecutorService executor = Executors.newFixedThreadPool(Math.min(tasks.size(), 10));
      List&lt;CompletableFuture&lt;JsonObject&gt;&gt; futures =
          tasks.stream()
               .map(t -&gt; CompletableFuture.supplyAsync(() -&gt; t.loadJsonObject(), executor))
               .collect(Collectors.toList());
  
      List&lt;JsonObject&gt; result =
          futures.stream()
                 .map(CompletableFuture::join)
                 .collect(Collectors.toList());
      long duration = (System.nanoTime() - start) / 1_000_000;
      System.out.printf("Processed %d tasks in %d millis\n", tasks.size(), duration);
      System.out.println(result);
      executor.shutdown();
  }
  </code></pre>
  
  <p>I am not sure how to continue from this. The VertX WebClient forces me to use an async handler, meaning I cannot return the JsonObject directly.</p>