title: When should I use a CompletionService over an ExecutorService?
body: <p>I just found CompletionService in <a href="http://www.chrisellsworth.com/blogs/devblog/archive/2006/10/31/Java-Concurrency-API-Example.aspx">this blog post</a>. However, this does't really showcases the advantages of CompletionService over a standard ExecutorService. The same code can be written with either. So, when is a CompletionService useful?</p>
  
  <p>Can you give a short code sample to make it crystal clear? For example, this code sample just shows where a CompletionService is not needed (=equivalent to ExecutorService)</p>
  
  <pre><code>    ExecutorService taskExecutor = Executors.newCachedThreadPool();
      //        CompletionService&lt;Long&gt; taskCompletionService =
      //                new ExecutorCompletionService&lt;Long&gt;(taskExecutor);
      Callable&lt;Long&gt; callable = new Callable&lt;Long&gt;() {
          @Override
          public Long call() throws Exception {
              return 1L;
          }
      };
  
      Future&lt;Long&gt; future = // taskCompletionService.submit(callable);
          taskExecutor.submit(callable);
  
      while (!future.isDone()) {
          // Do some work...
          System.out.println("Working on something...");
      }
      try {
          System.out.println(future.get());
      } catch (InterruptedException e) {
          e.printStackTrace();
      } catch (ExecutionException e) {
          e.printStackTrace();
      }
  </code></pre>