| Author |
destroy() method of servlets
|
kooskuntla venkat
Greenhorn
Joined: Sep 10, 2005
Posts: 11
|
|
|
Can we call destroy() method on servlets from service method?
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
Yes. But it wouldn't work that way. You shouldn't call that method, destroy method is called by container, instead. Please refer to the docs.
|
 |
Paul Bourdeaux
Ranch Hand
Joined: May 24, 2004
Posts: 783
|
|
I remember a post about this question being asked during an interview process... Only it was worded, "What will happen if you call the destroy() method from the service method?" In short, the answer is the container will execute whatever logic is in the destroy() method, and then return flow back to the service method, just like it would with any other method call. The point to remember here is that the destroy() method does not actually destroy the servlet as the name would imply. Instead, it is a place for you to put logic that should run when the container is preparing to destroy the servlet instance. For instance, if you needed to cleanup resources, this would be the place to do it. The container calls the destroy() method when the thread is no longer needed, and is about to be destroyed.
|
“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
|
 |
 |
|
|
subject: destroy() method of servlets
|
|
|