Forums Register Login

Servlet Life Cycle-Destroy method

+Pie Number of slices to send: Send
All,

Could you please explain under what circumstances a Servlet Container calls Destroy() method on a servlet instance?

Also could explain how a Servlet container maintains a pool of servlet instances, and how many servlet instances it creates on reading deployment descriptor?
+Pie Number of slices to send: Send
Your first question is answered by the javadocs for the Servlet interface.

As to the second question question, that is up to the servlet container to some degree. The spec demands that for all servlets having load-on-startup elements at least one instance is created. The container is free to create instances of the other servlets as well, or more than one instance for any servlet, but that's up to the implementation. I think it would be unusual for a container to take either of those actions, though. In particular, unless a servlet implements SingleThreadModel, no more than one instance is created (i.e., no pooling happens).
The moustache of a titan! The ad of a flea:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 600 times.
Similar Threads
Servlet's constructor
how to call destroy() method ?
use of init() in servlet life cycle
Servlet handling multiple requests
destroy()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:00:39.