• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can we call destroy method in servlet service method?

 
meher pradeep
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we call destroy method in servlet service method?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it didn't get mentioned explicitly: you can call the destroy (and init) method, but you absolutely should not.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic