title: Executor: Wait for specific tasks to finish
body: <p>The server application I am running gets multiple requests for tasks which I want to handle using a task system.</p>
  
  <p>Each task is represented as a <code>Runnable</code> that will demand <code>n</code> number of threads from a thread pool where <code>n</code> is smaller or equal to the thread pool size. The thread pool of course is necessary in order to <em>not</em> overload the CPU with too many threads. </p>
  
  <p>However, some of those tasks can be multi threaded and some can not. That is why it might be necessary for one task to wait for all its specific threads to finish in order to merge the results from those threads for the final result. </p>
  
  <p>If one uses multiple <code>Thread</code> instances one might join those like this:</p>
  
  <pre><code>try {
      // Wait for all threads to finish their tasks
      for (Thread thread : threads) {
          thread.join();
      }
  } catch (InterruptedException e) {
      e.printStackTrace();
  }
  
  // Finish job here ..
  </code></pre>
  
  <p>but I'd need something like this using <code>java.util.concurrent.Executor</code> or anything similar that works with a thread pool.</p>