title: ExecutorService FixedThreadPool as a shared parameter not running in parallel
body: <p>I am trying to use fixed thread pool in Java 8 which works perfect as long as it stays within the same function. Once I try sharing the executor as a parameter, it never runs in parallel. </p>
  
  <p>This works great: </p>
  
  <p>```</p>
  
  <pre><code>public static void test2() {
  
  ExecutorService executor =  Executors.newFixedThreadPool(2);
  try {
      CompletionService&lt;Integer&gt; myCompletionService = 
                 new ExecutorCompletionService&lt;Integer&gt;(executor);
  
  
      myCompletionService.submit(()-&gt; {
          try {
              TimeUnit.SECONDS.sleep(5);
              return 123;
          }
          catch (InterruptedException e) {
              throw new IllegalStateException("task interrupted", e);
          }
      });
  
  
      CompletionService&lt;Integer&gt; myCompletionService2 = 
                 new ExecutorCompletionService&lt;Integer&gt;(executor);
      myCompletionService2.submit(()-&gt; {
          try {
              TimeUnit.SECONDS.sleep(5);
              return 654;
          }
          catch (InterruptedException e) {
              throw new IllegalStateException("task interrupted", e);
          }
      });
  
      Future&lt;Integer&gt; myFuture = myCompletionService.take();
      Integer x = myFuture.get();
      System.out.println("Result = " + x);
  
      Future&lt;Integer&gt; myFuture2 = myCompletionService2.take();
      Integer y = myFuture2.get();
      System.out.println("Result = " + y);
  
      executor.shutdown();
  } catch (InterruptedException | ExecutionException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
  }
  }
  ```
  </code></pre>
  
  <p>But once I move these into three functions like: </p>
  
  <p>```</p>
  
  <pre><code>static Integer t1(ExecutorService executor) throws InterruptedException, ExecutionException {
      CompletionService&lt;Integer&gt; myCompletionService = 
                 new ExecutorCompletionService&lt;Integer&gt;(executor);
  
  
      myCompletionService.submit(()-&gt; {
          try {
              TimeUnit.SECONDS.sleep(5);
              return 123;
          }
          catch (InterruptedException e) {
              throw new IllegalStateException("task interrupted", e);
          }
      });
      Future&lt;Integer&gt; myFuture = myCompletionService.take();
      return myFuture.get();
  }
  
  static Integer t2(ExecutorService executor) throws InterruptedException, ExecutionException {
      CompletionService&lt;Integer&gt; myCompletionService2 = 
                 new ExecutorCompletionService&lt;Integer&gt;(executor);
  
  
      myCompletionService2.submit(()-&gt; {
          try {
              TimeUnit.SECONDS.sleep(5);
              return 456;
          }
          catch (InterruptedException e) {
              throw new IllegalStateException("task interrupted", e);
          }
      });
      Future&lt;Integer&gt; myFuture2 = myCompletionService2.take();
      return myFuture2.get();
  }
  
  static void test3() {
      ExecutorService executor =  Executors.newFixedThreadPool(5);
      try {
          Integer x = t1(executor);
          Integer y = t2(executor);
      } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (ExecutionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      executor.shutdown();
  }
  </code></pre>
  
  <p>```
  Now test3 will take 10 seconds, where I expected it to be the same as the top one which should take 5 seconds if things are running in parallel., </p>