Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

can we call destroy method in servlet service method?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can we call destroy method in servlet service method?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 502
jQuery Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic