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() doubt 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() doubt" Watch "destroy() doubt" New topic

destroy() doubt

Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166
Assuming that the Servlet Container has just called the destroy() method of a servlet instance,
which of the following statements are correct?

select 2 options

1. Any resources that this servlet might have held have been released
2. The servlet container time out has exceeded for this servlet instance.
3. The init() method has been called on this instance.
4. None of the requests can EVER be serviced by this instance.
5. All threads created by this servlet have ended.

answer is 3,4

why not 2,3,4,5?

and the explanation for this question is given below

the threads created by the servlet. The servlet container cannot kill any
threads created by a Servlet developer and has no idea whether they are finished or not.
Generally, servlets are not supposted to create new threads but a developer can do so if
Although option 2 is a possibility, it is not the only reason for calling destroy() on a servlet

question from enthuware

is it not the job of the container to create thread for each request? and they should when the thread has finished its job right?

correct me if i am wrong

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

There's the thread created FOR the servlet (which you were asking about). And then there's possible threads created BY the servlet (which the question was about). Not the same thing.
Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166
Hi paul

Thanks for your reply. why not option 2?

Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

Yes, for me also the option 2 seems to be a matching candidate.

But the answer you have posted says a related but confusing answer that 'it is not the only possible reason'.

Any inputs?

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Roland Benedek

Joined: Jun 06, 2008
Posts: 6
Maybe if the server or container the application is in, receives a shutdown command.
Or the application itself is undeployed.

I suppose each servlet in the running application will receive a request to shutdown and call destroy().

Could be wrong though.
Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166
Option 2 was given correct in whizlabs mock exam I took for the same question.
So I am confused. Please clarify my confusion.

I agree. Here's the link:
subject: destroy() doubt
It's not a secret anymore!