• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet.destroy() doubt

 
Tim Storms
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having a question about the destory() method of a servlet. This is what the api says:
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet.

If I understand this correctly, it says that a servlet is destroyed when there's no client using it (no threads). This doesn't seem right, because a servlet should always be accessible when someone requests it. Can somebody clarify this? Thanks!
 
Rancy Chadha
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

It is not the request threads that specs is talking about, it is talking about the threads initiated from the service method. There is a statement that is given in the portion you mentioned from specs: This method is only called once all threads within the servlet's service method have exited .
I hope your doubt is cleared now.
[ June 05, 2007: Message edited by: Rancy Chadha ]
 
Paul Clapham
Sheriff
Posts: 21565
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The full implication of the statement is that when the container decides to take a servlet out of service, it will wait until those conditions are true before calling destroy().

You seem to be interpreting it to mean that any time those conditions are true then the container will call the destroy() method.
 
Tim Storms
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, got it. Thanks for your replies.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rancy Chadha:
It is not the request threads that specs is talking about, it is talking about the threads initiated from the service method.


What kind of threads are initiated from the service method?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rancy Chadha:
It is not the request threads that specs is talking about, it is talking about the threads initiated from the service method. There is a statement that is given in the portion you mentioned from specs: This method is only called once all threads within the servlet's service method have exited .


I think you have that exactly the wrong way around - it is talking about the request threads. All of those that are currently executing the service method will be allowed to finish (remember, servlets are multi-threaded).

Other threads -which may have been started from the service method- are not affected by this.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic