shutdown hook for java web application

前端 未结 4 1990
闹比i
闹比i 2020-11-28 08:40

I need to save some data preferrably when the java web application is stopped, or when tomcat is stopped. how can this be done? Edit: any drawback if I use the jvm shutdown

4条回答
  •  死守一世寂寞
    2020-11-28 09:08

    As an addition to leonm's answer:

    If you use Spring, you can use Spring's "lifecycle management" to achieve a similar effect. For example, you can annotate a method in a bean with @PreDestroy to have it invoked automatically on container shutdown. That way, you don't need to put anything into the web.xml.

    See Spring beans factory lifecycle.

提交回复
热议问题