Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Question No: 10 (Question ID: 711) from jdiscuss

 
Ranch Hand
Posts: 445
  • 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?


Correct Ans:-
The init() method has been called on this instance.

None of the requests can EVER be serviced by this instance
But methinks it can be: -
All threads created by this servlet are done.
& also
Any resources that this servlet might hold have been released.
Comments or explanations anyone?
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet-container will wait until the threads that are running the service() method is done, then destroy() is called. you know, there may be multiple threads running the service() method of that servlet instance, because there were multiple HTTP requests came in.
Now, be careful it is the threads that is running the "service()" method. Not the threads the "service()" method created! If you servlet instance create some other threads in service(), they may be still running while destroy() is called! and servet-container do NOT care about those threads.
And, if your servlet instance does not release some of the resouces in destroy(), then of course even after destroy() is called, some resource are still not released.
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. The init() method has been called on this instance. True. The container has to guarantee that the init() method finishes properly before this servlet instance can be ready to service a request.
2. None of the requests can EVER be serviced by this instance. True. the container must also guarantee that this servlet instance that just called destroy() can no longer service requests.
3. All threads created by this servlet are done. A container may dispose a servlet instance, i.e. call destroy(), even if this servlet instance has never serviced any threads.
4. Any resources that this servlet might hold have been released. It falls upon the developer to maintain resources. Though resources can be released in service(), the usual place to do it is in destroy().
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add to #3, a server has timeout factor too:


SRV.2.3.4 End of Service
The servlet container is not required to keep a servlet loaded for any particular period of time. A servlet instance may be kept active in a servlet container for a period of milliseconds, for the lifetime of the servlet container (which could be a number of days, months, or years), or any amount of time in between...
For example, the container may do this when it wants to conserve memory resources, or when it
itself is being shut down. Before the servlet container calls the destroy method, it must allow any threads that are currently running in the service method of the servlet to complete
execution, or exceed a server defined time limit.

 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic