Calling servlet's destroy method

前端 未结 8 1609
执念已碎
执念已碎 2021-01-01 16:03

As per the link http://www.xyzws.com/Servletfaq/when-is-destroy-of-servlets-called/20, one of the reason of calling destroy method is when the servlet hasn\'t got a

8条回答
  •  粉色の甜心
    2021-01-01 16:38

    Servlet.destroy()'s javadoc says: "Called by the servlet container to indicate to a servlet that the servlet is being taken out of service". It doesn't specify what situations would cause a servlet to be "taken out of service", it is simply an event to which you can react to if you need to. For example you might want to close some resources you have open, or persist some state to storage.

    The most obvious reason for this is that the servlet container is being shut down, but a container could equally well decide that it's time to unload a servlet because it's not been used in a month and is simply consuming resources. That behaviour is entirely up to the implementation, and it is not something you (as a servlet designer) should be concerned about.

提交回复
热议问题