Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

destroy() doubt

 
Srividhya Kiran
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
required.
Although option 2 is a possibility, it is not the only reason for calling destroy() on a servlet
instance.

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

Thanks
Srividhya
 
Paul Clapham
Sheriff
Pie
Posts: 20958
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi paul

Thanks for your reply. why not option 2?

Srividhya
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Roland Benedek
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 2 was given correct in whizlabs mock exam I took for the same question.
So I am confused. Please clarify my confusion.

Thanks
Srividhya
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic