当应用程序停止/卸载时,有没有办法在Tomcat6上执行代码?(由于内存泄漏问题,我正在尝试手动注销MySQL驱动程序)。
提前感谢
发布于 2010-11-10 13:47:54
使用ServletContextListener是处理这类事情的标准过程。
它有两个有用的方法:一个是在应用程序初始化期间激发的,另一个是在应用程序关闭期间激发的。它们分别是,
void contextInitialized(ServletContextEvent sce) 和
void contextDestroyed(ServletContextEvent sce) 您将需要使用第二个来进行清理。
实现上面提到的接口:
package com.myapp
public class AppListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent sce)
{
// Application shuts down. Put your cleanup code here.
}
public void contextInitialized(ServletContextEvent sce)
{
// Application starts up.
}
}并在web.xml中注册它
<web-app>
<listener>
<listener-class>
com.myapp.AppListener
</listener-class>
</listener>
</web-app> 发布于 2010-11-10 13:35:07
注册ServletContextListener。
https://stackoverflow.com/questions/4141475
复制相似问题