title: ExecutorService's shutdown() doesn't wait until all threads will be finished
body: <p>I have a code where 4 threads run at the same time. I want to wait until all these 4 threads will be finished. And only after that to continue the app flow.</p>
  
  <p>I tried two approaches:</p>
  
  <ol>
  <li><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html#join--" rel="noreferrer"><strong><code>Thread#join()</code></strong></a>, this approach works as expected. The code, which comes after <code>join()</code> is executed only after all threads are finished.</li>
  <li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html#shutdown--" rel="noreferrer"><strong><code>ExecutorService#shutdown()</code></strong></a>, this technique allows executing code, which comes after <code>shutdown()</code> even if not all threads are finished.</li>
  </ol>
  
  <p>Code sample:</p>
  
  <pre><code>ExecutorService service = Executors.newFixedThreadPool(cpuCoresNum);
  
  for (int i = 0; i &lt; cpuCoresNum; i++) {
  
      service.submit(() -&gt; {
          try {
              foo(); // some long execution function
          } catch (Exception e) {
              e.printStackTrace();
          }
      });
  }
  
  service.shutdown();
  
  System.out.println("We're done! All threads are finished!");
  </code></pre>
  
  <p><strong>My question:</strong></p>
  
  <ul>
  <li>Why <code>submit()</code> and <code>shutdown()</code> don't wait until all threads will be finished and prints <em>«We're done! All threads are finished!»</em> right after call of <code>service.shutdown();</code>?</li>
  </ul>