title: Creating ThreadPoolExecutor in spring cause memory leak?
body: <p>I am working with Spring, and in a <code>RequestMap</code> method I have code like below:</p>
  
  <pre><code>@RequestMap
  public void someMethod() {
      ThreadPoolExecutor executor = Executors.newFixedThreadPool(N);
      executor.submit(new Runnable());
      executor.submit(new Runnable());
  }
  </code></pre>
  
  <p>Then I keep get OOM error even every <code>Runnable</code> should be finished in seconds. After analysing the heap dump, I found there are thousands <code>Thread</code> objects.</p>
  
  <p>Then I changed <code>executor</code> to singlton with <code>Executors.newCachedThreadPool</code>, this problem was fixed.</p>
  
  <p>As far as my understand, after the method returned, there is no reference to the thread pool, so it should be garbage-collected, but the fact is the thread still on the heap. Why?</p>