Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

destroy() method

 
tilak kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we call destroy() method forcefully ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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?
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The destroy() method will be called for you at the appropriate time by the container.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tilak kumar:
Can we call destroy() method forcefully ?


Yes. Check it out.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • 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
 
Sripathi Krishnamurthy
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Sandeep Saha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do you want to call the destroy() method anyway?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic