title: Waiting for all the threads to finish before shutting down the Executors
body: <p>Here is my code snippet.</p>
  
  <pre><code>ExecutorService executor = Executors.newFixedThreadPool(ThreadPoolSize);
  while(conditionTrue)
  {
  ClassImplementingRunnable c = new ClassImplementingRunnable();
  executor.submit(c);
  }
  </code></pre>
  
  <p>Now after this is do</p>
  
  <pre><code>executor.shutdown();
  </code></pre>
  
  <p>What i want to achieve here is that i want to wait for all the threads in the threadpool to have finished the execution and then i want to shutdown the executor. </p>
  
  <p>But i guess this is not what is happening here. The main thread seems to be executing shutdown and it just shuts down everything.</p>
  
  <p>Before when my threadpool size was 2, i did the following and it seemed to work.</p>
  
  <pre><code>ClassImplementingRunnable c1 = new ClassImplementingRunnable();
  executor.submit(c1);
  ClassImplementingRunnable c2 = new ClassImplementingRunnable();
  executor.submit(c2);
  Future f1 = executor.submit(c1);
  Future f2 = executor.submit(c2);
  while(!f1.done || !f2.done)
  {}
  executor.submit();
  </code></pre>
  
  <p>How do i do this for a greater number of threads in the threadpool?
  Thanks.</p>