Hello Experts! Two basic questions: 1. Can we override/overload destroy method of a servlet? 2. What will happen if we give a call to the destroy method from the service method of a servlet? Regards, Anupreet
Of course, we can override/overload the destroy method, so that this method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet�s current state in memory. But I'm not sure about your second question, but I hope we can call destroy method from service method...For example, we may want a servlet to be destroyed, when there is an error occurred or some other reasons... But I'm not quite sure about it... Just my opinion...
You can certainly call the destroy method from other methods of the servlet. It will execute the code present in the destroy method. This will not destroy the servlet instance. The destroy is supposed to be called by the container. When it calls the servlet will be ready for retirement. [ November 13, 2003: Message edited by: Pradeep Bhat ]
Pradeep, you got reasonabe explanation... It is not usual to call destroy method from other methods, it's supposed to be called by the container instead... Anupreet, can I ask you why you want to deal with the destroy method, since it will be handled by the container itself?
ko ko and pradeep!!!Thanks This is a Interview question......what will happen if destroy called from the service method??? normally people will say it will throw exception,it will destroy and so on....This is a good information.