• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what happend,when we call destroy() in 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
what happend,when we call destroy(), in service() method?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you call the destroy method, the destroy method gets called. Is this what you expected?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you wanted to know does this cause the servlet to be unloaded or similar? No it does not. The confusion here is in cause and effect - the servlet going out of service causes the destroy() method to be called and gives you achance to clean up resources. Calling the destroy method does not cause it to be unloaded.

Dave
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dont worry , the Servlet won't die.
 
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
In simple terms:
The destroy method is not there for you to call.
It's there for the servlet container to call.

If you want something to happen when your servlet is destroyed (logging, cleaning up open file handlesn, etc...), put some code in the destroy method and the container will run it when the servlet is destroyed. Mostly, this happens when the app is stopped or reloaded.
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have feeling that servlet specification 2.6 should include methods to unload servlet. I notice that question about destroy is so frequently asked. From other side probably destroy needs to be renamed to something more clue giving, like onPreUnload().
 
Author
Posts: 836
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have feeling that servlet specification 2.6 should include methods to unload servlet.

But why would a servlet author want to unload a servlet themselves when the entire life cycle is maintained by the container? Wouldn't this leave the container a bit puzzled about what to do with requests coming to that servlet?

From other side probably destroy needs to be renamed to something more clue giving, like onPreUnload().

Note the use of the @PreDestroy annotation now available in Java EE 5 which replaces the need for an explicit destroy() method (although that's still in the interface contract). You could therefore have a method:
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by dema rogatkin:
I have feeling that servlet specification 2.6 should include methods to unload servlet.



Why? You can easily take a servlet out of service by throwing an UnavailableException.
[ June 01, 2006: Message edited by: Bear Bibeault ]
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it's helpful.
 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic