This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

destroy() question

 
Ricardo Cortes
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question is taken from JWebPlus and I am a little confused by one of the answers.
"Assuming that the Servlet Container has just called the destroy() mthod of a servlet instance, which of the following statements are correct"?
Answer: The servlet container time out has exceeded for this servlet instance.
Is the destroy() method only called when the session has timed out or has been invalidated using invalidate()? I thought the container could remove the instance of a servlet to converse memory and thus the destory() method would be called in this case as well. Help!
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not what it says -- it's not referring to session timeouts. I would agree that the wording is confusing. The servlet lifecycle has absolutely nothing to do with the session lifecycle.
The servlet container calls destroy() when it wants to remove the servlet to conserve memory (or because the server shuts down). Typically, a container will do this if a servlet has not been accessed for a while; this is the "timeout" the answer refers to. But this is an implementation detail of the container and not part of the spec, so really I think the answer should be reworded.
- Peter
 
Ricardo Cortes
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah! That totally makes sense Peter. I guess it all came down to what "timeout" they were talking about. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic