• Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions about the servlet lifecycle methods  RSS feed

 
Gobinath Manoj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The container call init(), and destroy() only once in his life. init() willl call when the 1st req given to servlet.

Then each time my service() only called. when my destroy() method will be called. each req working under seperate thread, after thread completed it will not call destroy() so when des() called.

[ October 17, 2007: Message edited by: Ben Souther ]
[ October 17, 2007: Message edited by: Bear Bibeault ]
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Gobinath
The container call init(), and destroy() only once in his life. init() willl call when the 1st req given to servlet.


Its not always called on first request, if you have load-on-startup defined for the servlet the servlet will be initialized on loading and not on first request to it.

When the container wants to remove the servlet instance from the memory then and then only destroy is called, if all the threads servicing the requests are done the container may not necessarily remove the servlet instance, the container will do it when it needs to free up the memory or is shutting down.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gobinath Manoj,
Welcome to JavaRanch!

In an effort to help you get the most from our forums, we've compiled a
list of tips for asking questions here. You can find the list in our
FAQ section here.
In particular please see:
UseAMeaningfulSubjectLine
I've changed the subject line for you.

UseRealWords

Abbreviations such as "u" or "ur" in
place of "you" and "you are" or "you're" confound language translation software making
it hard for our non-English speaking members to read your posts.
"plz" is not a word in the English language.

Again, welcome to JavaRanch and good luck with your question.
-Ben
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!