File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes destroy() question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "destroy() question" Watch "destroy() question" New topic

destroy() question

Ricardo Cortes
Ranch Hand

Joined: Jan 23, 2002
Posts: 140
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!

Sun Certified J2EE Architect for the J2EE Platform (Part 1)<br />Sun Certified Web Component Developer for the J2EE Platform<br />Sun Certified Programmer for the Java 2 Platform
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Jan 23, 2002
Posts: 140
Ah! That totally makes sense Peter. I guess it all came down to what "timeout" they were talking about. Thanks.
I agree. Here's the link:
subject: destroy() question
jQuery in Action, 3rd edition