wood burning stoves 2.0*
The moose likes Servlets and the fly likes when would a servlet be destroyed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "when would a servlet be destroyed" Watch "when would a servlet be destroyed" New topic
Author

when would a servlet be destroyed

Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
I was faced with this question and answered it saying whenever the servlet container deemed necessary - during shutdown or when it needs to free memory resources. However, the interviewer wasn't not satisfied with this response.
Thoughts...?


- Sathvathsan Sampath
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
When taken out of service, for example when we stop our web application.
Mohnish Chaudhary
Greenhorn

Joined: Sep 19, 2005
Posts: 2
Sathvathsan, your reply was correct. It's when either the servlet is destroyed or when the servlet container has to do it to free some resources.
Aniruddha Mukhopadhyay
Ranch Hand

Joined: Nov 15, 2000
Posts: 59
Servlet container shutting down definitely calls the destroy method of servlet. If servlet container needs some free memory, it would call destroy method for those servlets whose service method have exited or after a timeout period has passed.


Aniruddha
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Sathvathsan Sampath:
I was faced with this question and answered it saying whenever the servlet container deemed necessary - during shutdown or when it needs to free memory resources. However, the interviewer wasn't not satisfied with this response.
Thoughts...?


What do you mean when you say he wasn't satisfied?
What was his reaction to your answer?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sathvathsan Sampath
Ranch Hand

Joined: Oct 03, 2000
Posts: 96
By Ben Souther
What was his reaction to your answer?

He responded asking, ´┐ŻBesides a shut down or freeing memory resources when exactly would the container destroy a servlet?´┐Ż
He wanted me to be very specific and detailed. I didn't have a clue. He believed I just scratched the surface saying the above. When I asked him what his response would be to this he refused to answer! I want to understand how more there is to this.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

He may have wanted you to say:
Before the webapp is reloaded or stopped and before the contextDestroyed event of any context listeners is fired.

He may also have wanted to see if you would mistakenly say:
Whenever servletDestroyed is called.
Jack Wiesenthaler
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
I think your answer was reasonable.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
When you deploy a new one? You can do that without stopping the server, right?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
Consider Paul's rocket mass heater.
 
subject: when would a servlet be destroyed
 
Similar Threads
Filter and servlet
how many servlets needed?
when init() method is called ?
Servlet Error when deploy with tomcat
release() in custom tag !!