Reputation: 1190
Can the servlet be destroyed only using the destroy() method called by the contains or is there any other way
Upvotes: 0
Views: 298
Reputation: 85789
The servlet is not destroyed when you call destroy
method. This method is meant to clear any resources used by the servlet (initialized in init
method, hopefully). The Servlet container is in charge of the lifecycle of the object reference and will call the destroy method before freeing the object reference.
Calling the destroy
method in the object reference of your servlet won't assure the servlet will be removed from the memory.
The Servlet API doesn't provide a method to unregister servlets. This is the work of the servlet container. The javadoc of Servlet
states it:
This interface defines methods to initialize a servlet, to service requests, and to remove a servlet from the server. These are known as life-cycle methods and are called in the following sequence:
- The servlet is constructed, then initialized with the
init
method.- Any calls from clients to the
service
method are handled.- The servlet is taken out of service, then destroyed with the
destroy
method, then garbage collected and finalized.
Which means, not even calling the destroy
method assures the servlet will be destroyed.
Upvotes: 2
Reputation: 1601
Either by calling destroy method or by shutting down the server.
Upvotes: 0