title: How to shutdown ThreadPoolExecutor in spring bean when tomcat is shutdown?
body: <p>I create a threadpoolexecutor in a spring bean, so I need to shutdown this executor when tomcat is shutdown. </p>
  
  <pre><code>     public class PersistBO implements InitializingBean {
  
  private ThreadPoolExecutor executer;
  
  public void shutdownExecutor() {
      executer.shutdown();
  }
  
  @Override
  public void afterPropertiesSet() throws Exception {
      taskQueue = new LinkedBlockingQueue&lt;Runnable&gt;(queueLength);
      executer = new ThreadPoolExecutor(minThread, maxThread, threadKeepAliveTime, 
              TimeUnit.SECONDS, taskQueue, new ThreadPoolExecutor.DiscardOldestPolicy());
  }
  </code></pre>
  
  <p>I have searched solution on google and get a result. That is to add a shutdownhook to java.lang.runtime. However, the java docs says  java.lang.Runtime#shutdownHook is called when the last non-daemon thread exits. So it is a dead lock.  Is there any solution to shutdown executor in spring bean? </p>