Calling servlet's destroy method

前端 未结 8 1562
执念已碎
执念已碎 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:56

    From the specification (The Servlet Interface -> Servlet Life Cycle -> End of Service):

    Once the destroy method is called on a servlet instance, the container may not route other requests to that instance of the servlet. If the container needs to enable the servlet again, it must do so with a new instance of the servlet’s class.

    The specification is referring to a particular instance of the servlet that is being destroyed.

    So, does that mean destroy will be called and they will be no longer used?

    It doesn't mean that the servlet whose instance is destroyed is never used. It's only that particular instance that is not used as it would have been garbage collected. When a request comes in for that servlet, the container would create a new instance of that servlet and performs all the life-cycle actions till serving the request, again.

提交回复
热议问题