线程的回收

在tomcat容器中,在使用EWS时,在jar包common-http-client.jar去和exchange server连接,它启动了一个线程名叫”MultiThreadedHttpConnectionManager cleanup“,然后所有的connection都是在这个线程上完成的,当undeploy这个模块时,这个线程确没有关闭,提示警告:appears to have started a thread named [MultiThreadedHttpConnectionManager cleanup] but has failed to stop it. This is very likely to create a memory leak.

所以需要关闭这个线程。

 

于是我在undeploy的时候添加一个监听,在接口ServletContextListener 中实现contextDestroyed方法。

1. 添加以下内容在web.xml

 

<listener>
      <listener-class>com.tsystems.showcase.calendar.listener.PortletUndeployListener</listener-class>
  </listener>

 

 

2. 新建类PortletUndeployListener 实现接口ServletContextListener .

public class PortletUndeployListener implements ServletContextListener {

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        MultiThreadedHttpConnectionManager.shutdownAll();
    }

    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        // Do nothing.
    }
}

 

你可能感兴趣的:(线程)