java web应用程序的关闭钩子 [英] shutdown hook for java web application
本文介绍了java web应用程序的关闭钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要最好在java web应用程序停止时或tomcat停止时保存一些数据.如何才能做到这一点?如果我使用 jvm 关闭钩子有什么缺点吗?
I need to save some data preferrably when the java web application is stopped, or when tomcat is stopped. how can this be done? any drawback if I use the jvm shutdown hook?
推荐答案
使用实现 ServletContextListener 在您的 web.xml 中:
Use a class that implements ServletContextListener in your web.xml:
<web-app>
<!-- Usual stuff here -->
<listener>
<listener-class>com.mycompany.MyClass</listener-class>
</listener>
</web-app>
这篇关于java web应用程序的关闭钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文