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 have some resources that I allocate when my web service is created that
Share
I suggest using a
ServletContextListenerfor this. Write a custom implementarion of that interface which does what you want, and then hook it into yourweb.xmlusing the<listener>element (example).This lifecycle doesn’t exactly match that of the servlet, but it should be close enough for your purposes.