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
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?
Joined: Mar 07, 2005
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.
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.