contextInitialized和contextDestroyed的问题?
我现在用的开发工具是wsad,开发中遇到如下情况:
public class XmlListion extends HttpServlet implements ServletContextListener {
/* (非 Javadoc)
* @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
*/
public void contextInitialized(ServletContextEvent arg0) {
// TODO 自动生成方法存根
System.out.println("test============contextInitialized");
sleepTime = configInfo.getPropertiesValue("parameter","SleepTime");
rt = new XmlTimer(Integer.parseInt(sleepTime));
rt.start();
}
/* (非 Javadoc)
* @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
*/
public void contextDestroyed(ServletContextEvent arg0) {
// TODO 自动生成方法存根
System.out.println("test============contextDestroyed");
if (rt != null) {
rt.stop();
}
}
}
在网上看过很多文章说,contextInitialized和contextDestroyed是根据服务的启动而启动或者关闭的,但是实际上我在用websphere重新发布一个版本时,有时候会出现上面的代码中调用的定时器会没有关闭,而且这个进程会出现耗用99。99%的cpu以至于服务会死掉,请问大家有什么好的方法能不能帮帮我,多谢了!