自由狼-台风0
[Java-Web]如何在ServletContext销毁时执行特定操作?
环境为Tomcat5/6。
ServletContext销毁时需要释放服务器上的非Java资源(关闭日志文件)。
我目前的办法是设置监听器。在ServletContext销毁时监听器的“public void contextDestroyed(ServletContextEvent sctx)”会被调用。
问题是,“public void contextDestroyed(ServletContextEvent sctx)”[b]大多数时候似乎[color=Red]只执行一半[/color][/b](从头到尾设置打印语句,尾部的打印语句未执行),无法保证资源释放(文件资源是否正常释可通过与其对应的.lck文件是否消失来判断)。
有没有什么办法[color=Red][b][u]保证[/u][/b][/color]ServletContext销毁时所指定的操作能正常完成?
[[i] 本帖最后由 自由狼-台风0 于 2008-6-25 15:25 编辑 [/i]]