• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

destroy() doubt

 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi paul

Thanks for your reply. why not option 2?

Srividhya
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic