开发者

JAX-WS Servlet destroy()

开发者 https://www.devze.com 2023-01-17 21:07 出处:网络
I have some resources that I allocate when my web service is created that I need to be released (for example, I need to flush and close file streams when the servlet is being shut down).How can I have

I have some resources that I allocate when my web service is created that I need to be released (for example, I need to flush and close file streams when the servlet is being shut down). How can I have开发者_开发知识库 code executed when the JAX-WS servlet's destroy() method is called?


I suggest using a ServletContextListener for this. Write a custom implementarion of that interface which does what you want, and then hook it into your web.xml using the <listener> element (example).

This lifecycle doesn't exactly match that of the servlet, but it should be close enough for your purposes.


I just want to mention that you can annotate a method with @PreDestroy; from the JavaDoc:

The PreDestroy annotation is used on methods as a callback notification to signal that the instance is in the process of being removed by the container. The method annotated with PreDestroy is typically used to release resources that it has been holding. [...]

See Creating a Simple Web Service and Clients with JAX-WS

0

精彩评论

暂无评论...
验证码 换一张
取 消