title: Java 8 CompletableFuture future is waiting needlessly for other futures
body: <p>I have this simple code below. All futures should start at the same time. <code>future13</code> is supposed to run right after futures 1 and 3 finish, but in the logs I see that it waits until after futures 1, 2, 3, and 4 all finish. Why does it wait for futures 2 and 4?</p>
  
  <pre><code>import java.util.concurrent.CompletableFuture;
  import java.util.concurrent.ExecutionException;
  
  import org.junit.Test;
  
  
  public class Test1 {
  
      private void loop(Long id, int max) {
          try {
              for (int i = 0; i &lt; max; i++) {
                  System.out.println(id);
                  Thread.sleep(100);
              }
          } catch (Throwable t) {
              System.out.println(t);
          }
      }
  
      private CompletableFuture&lt;Void&gt; createConfigFuture(Long id) {
          return CompletableFuture.supplyAsync(() -&gt; {
              loop(id, 100);
              return null;
          });
      }
  
      @Test
      public void testMe() {
          CompletableFuture&lt;Void&gt; future1 = createConfigFuture(1L);
          CompletableFuture&lt;Void&gt; future2 = createConfigFuture(2L);
          CompletableFuture&lt;Void&gt; future3 = createConfigFuture(3L);
          CompletableFuture&lt;Void&gt; future4 = createConfigFuture(4L);
  
          try {
              CompletableFuture&lt;Void&gt; future13 = CompletableFuture.allOf(future1, future3)
                  .thenApply(v -&gt; {
                      loop(999L, 5);
                      return null;
                  });
              CompletableFuture&lt;Void&gt; mainFuture = CompletableFuture.allOf(future13, future2, future4);
              mainFuture.get();
  
          } catch (InterruptedException | ExecutionException e) {
              System.out.println(e);
          }
      }
  }
  </code></pre>