• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

destroy() method

 
Greenhorn
Posts: 15
  • 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 forcefully ?
 
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
destroy() doesn't actually destroy anything.
It's just a place for you to put code that you want called before a servlet is destroyed.
The container calls it for you.

What is it you're trying to do?
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The destroy() method will be called for you at the appropriate time by the container.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by tilak kumar:
Can we call destroy() method forcefully ?



Yes. Check it out.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet "lifecycle" methods like init and destroy should never be called by the programmer. See the discussion in javax.servlet.Servlet JavaDocs.
If you think your servlet architecture requires such a thing, you better go back to the drawing board.
Bill
 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,
There was a requirement for starting some server first time a servlet is called and it was done in init method. It gave no problems and is running fine till today. Also in the destroy method, the stop server method is called which will stop the server(in case the server has not stopped earlier).
These were done in tomcat and is working fine. So now I dont understand what is problem in using init and destroy. I referred to servlet javadocs and I couldnt find anything mentioned as not to use the init and destroy methods in code.
Can you please throw more light on why these cant be used?

Thanks
Sripathi
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
William,
I am very sorry for being confused. I think you meant that one should not call the init and destroy method in the code. But there is no harm in using them(which means the container will call init and destroy when required).
Sorry again for being confused.

Thanks
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sripathi,
I do aggree with william. Destroy is a method that a user can call. But it is not recomanded. Destroy method is used when we want to do something at the end of the servlet lifecycle and is called by the container.So avoid calling destroy method always.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why do you want to call the destroy() method anyway?
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic