To the best of my knowledge its not the container, its for the servlet developer to free any held resources in destroy method.
That is when the destroy method is called, the resources which was hold by the developer will be released.Is it true?(Just I am confused whether the resources held by the container or servlet developer will be released when the destroy() is called.) Thank you,
Description in javadocs: Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet.
This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.
If you read the second paragraph it says that it gives a chance to servlet. So its the servlet developer's responsibility to close any open connections, handles etc in the destroy method.
hai though the servlet container is called the servlet destroy() at the end of life cycle.you should hard cade it what are all the resources should be released.This is the one way to accept and another way is the REQUEST and RESPONSE object is killed at the end of the destroy() so all resources is released autometically....
Originally posted by mgnaresh mgnaresh: This is the one way to accept and another way is the REQUEST and RESPONSE object is killed at the end of the destroy() so all resources is released autometically....
The destroy method is called when there is no active request, so request and response objects are not relevant to it.
Originally posted by padmapriyagururajan priya: Do you mean to say that the destroy() method releases the resources and not the developer.
The default destroy method (which does nothing) can be overridden by the developer in order to perform any cleanup necessary. Nothing happens in it unless the developer codes it first; it's just that the method is called automatically by the container, like the init method is called before the first request.