aspose file tools*
The moose likes Servlets and the fly likes destroy() related question.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "destroy() related question.." Watch "destroy() related question.." New topic
Author

destroy() related question..

h kumar
Greenhorn

Joined: Jul 03, 2007
Posts: 13
Hi Friends,

Pleasw tell me can i write destoy() method inside a service() method of a servlet?
if yes what is the need of that?

Thanks
Hari
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
Originally posted by h kumar:
Hi Friends,

Pleasw tell me can i write destoy() method inside a service() method of a servlet?
if yes what is the need of that?

Thanks
Hari


You can't put any method inside another. I think you want to know if you need to implement the destroy() method in a servlet. It's not required unless you have some cleanup to be done; the destroy() method is called just before the servlet instance is unloaded and put out of service.

For example, if you were opening a connection in the servlet's init() method for use throughout the life of the servlet, you'd want to close() the connection and free up resource when the servlet was done running. You'd put this code in the destroy() method.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I believe the question is "Can we call the destroy() method directly from the service method"

The answer is yes, but there is no real reason to do so. This question has been asked a few times if you would like to search, but I'm not sure why it keeps coming up...
 
Don't get me started about those stupid light bulbs.
 
subject: destroy() related question..