title: ExecutorService, how to wait for all tasks to finish
body: <p>What is the simplest way to to wait for all tasks of <code>ExecutorService</code> to finish? My task is primarily computational, so I just want to run a large number of jobs - one on each core.  Right now my setup looks like this: </p>
  
  <pre><code>ExecutorService es = Executors.newFixedThreadPool(2);
  for (DataTable singleTable : uniquePhrases) {   
      es.execute(new ComputeDTask(singleTable));
  }
  try{
      es.wait();
  } 
  catch (InterruptedException e){
      e.printStackTrace();
  }
  </code></pre>
  
  <p><code>ComputeDTask</code> implements runnable.  This appears to execute the tasks correctly, but the code crashes on <code>wait()</code> with <code>IllegalMonitorStateException</code>.  This is odd, because I played around with some toy examples and it appeared to work.  </p>
  
  <p><code>uniquePhrases</code> contains several tens of thousands of elements.  Should I be using another method?  I am looking for something as simple as possible</p>