The destroy() method.
Finally a servlet can also override
public void destroy() {. . .}
If the Web server terminates gracefully, it will invoke destroy() on all servlet instances it holds before shutting down.
In principle, this is a place where you can put code to back-up the current state of the servlet to persistent storage. The servlet can restart from restored state when the Web server is restarted.
In practice, servers (especially Tomcat!) often terminate “ungracefully”, when the system crashes or the server process is killed. Relying on destroy() methods being called is probably not advisable.