title: Why doesn't this thread pool get garbage collected?
body: <p>In this code example, the ExecutorService is used one and allowed to go out of scope.</p>
  
  <pre><code>public static void main(String[] args)
  {
      ExecutorService executorService = Executors.newFixedThreadPool(3);
      executorService.submit(new Runnable()
      {
          public void run()
          {
              System.out.println("hello");
          }
      });
  }
  </code></pre>
  
  <p>Once executorService is out of scope, it should get collected and finalized. The finalize() method in ThreadPoolExecutor calls shutdown().</p>
  
  <pre><code>/**
   * Invokes {@code shutdown} when this executor is no longer
   * referenced and it has no threads.
   */
  protected void finalize() {
      shutdown();
  }
  </code></pre>
  
  <p>Once shutdown() is called, the pool threads should terminate and the JVM should be allowed to exit. However the executorSerivce is never getting collected and thus the JVM stays alive. Even calls to System.gc() don't seem to work. Why isn't executorService getting collected even after main() terminates?</p>
  
  <p>Note: I know I should call shutdown() myself and I always do outside of testing. I'm curious why finalization isn't working as a back-up here.</p>