my dog learned polymorphism*
The moose likes Servlets and the fly likes can we call destroy method in servlet service method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "can we call destroy method in servlet service method?" Watch "can we call destroy method in servlet service method?" New topic
Author

can we call destroy method in servlet service method?

meher pradeep
Greenhorn

Joined: Dec 13, 2006
Posts: 1
can we call destroy method in servlet service method?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I'm not sure why but this question gets asked a lot.
Search this forum with keyword "destroy" and you will find plenty of discussions on the subject.

This question indicates a gap in your understanding of the servlet life-cycle and the methods involved.
There is a link to the servlet spec in my signature.
The first few chapters cover this.
In particular, look at SRV.2.3


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Purpose of destroy() method is to know when servlet is going out of service OR In other words, before container decides to take out servlet from service, it will call this method, so that you can do your clean up process.

servlet life-cycle is init() --> service(..) --> destroy() which is maintained by servlet Container and it doesn't make any sense to call these methods explicitly.

May I know why you want to this?

BTW, as Ben advice and my suggestion also read Servlet Specification, which will make you more clear.


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41149
    
  45
Since it didn't get mentioned explicitly: you can call the destroy (and init) method, but you absolutely should not.


Ping & DNS - my free Android networking tools app
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
destroy is a call back method and container is suppose to call that not you .But as you have asked whether this can be invoked , yes you can.But that would be just as any other method call.The purpose of destroy method is not that.


Rahul Bhattacharjee
LinkedIn - Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can we call destroy method in servlet service method?
 
Similar Threads
destroy method
Question on Servlet Redirection
destroy method
Servlet
destroy() method of servlets