title: Execute a for loop in parallel using CompletableFuture in Java and log the execution
body: <p>I have a for loop which I am trying to parallelize using CompletableFuture.</p>
  
  <pre><code>for (int i = 0; i &lt; 10000; i++) {
      doSomething();
      doSomethingElse();
  }
  </code></pre>
  
  <p>What I have till now is:</p>
  
  <pre><code>for (int i = 0; i &lt; 10000; i++) {
      CompletableFuture.runAsync(() -&gt; doSomething());
      CompletableFuture.runAsync(() -&gt; doSomethingElse());
  }
  </code></pre>
  
  <p>I guess this serves the purpose but there is a requirement to print log just before the start and end of all the processing. If I do this:</p>
  
  <pre><code>log("Started doing things");
  for (int i = 0; i &lt; 10000; i++) {
      CompletableFuture.runAsync(() -&gt; doSomething());
      CompletableFuture.runAsync(() -&gt; doSomethingElse());
  }
  log("Ended doing things");
  </code></pre>
  
  <p>Does this guarantee that the second log statement will be printed once all the for loop is over since that is executing in a separate thread? If not, is there a way to do this without blocking the main thread?</p>