• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

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


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?
 
Kyle Tang
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • 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.
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic