Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

destroy() related question..

 
h kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic