• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

destroy() question

 
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!
 
author
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.
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic