Series: Subject: Topic:
Question: 88 of 177

Can we call destroy() method on servlets from service method?

Asked by: lats13 | Member Since Dec-2005 | Asked on: Mar 18th, 2006

View all questions by lats13

Showing Answers 1 - 9 of 9 Answers

Answered On : Mar 21st, 2006

View all answers by dikesh

Yes we can call

Login to rate this answer.

Answered On : Mar 21st, 2006

View all answers by vai_ir

Yes we can call destroy method implecitlly from service method.

Login to rate this answer.

Answered On : Apr 4th, 2006

No we can not call destroy() method

Login to rate this answer.

Answered On : Apr 4th, 2006

View all answers by Jinnovator

Yes, we can call for sure. Behind the scenes we are calling one method from another for the same object. Can be done but is disastrous and can lead to strange behaviour ! Try it out if you wanna !

Login to rate this answer.
siva kumar

Answered On : Apr 19th, 2006

Hi , we can call the destroy() method. but it works like normal method , for example ,if u have one method in ur servlet class like show(), it acts like show() method. whenever we click on the stop link in manager page of that particular application,then only application will be stopped and it calls the destory method. At that time only the application objects permenantly destroyed.sample code: Try it out..public class TestServlet extends HttpServlet implements SingleThreadModel{ public void init(){ System.out.println("hello in init"); } public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ PrintWriter out=response.getWriter(); out.println("Selected Button Name :"+request.getParameter("button")); } public void destroy(){ System.out.println("Hello in destroy"); }}

Login to rate this answer.

Answered On : Apr 21st, 2006

Yes,we can call destroy method in service method,

Login to rate this answer.
Ashok Kumar Dash

Answered On : May 12th, 2006

Hi, we can call the destroy() inside the sevice method.But in according to me from the point when we will call destroy(),then the servlet will be destroyed.But better we should implement and check it out.

Login to rate this answer.
Shikha Dixit

Answered On : May 17th, 2006

Yes, we can call destroy() method from service() method but it will be treated as any other normal method rather lifecycle method. Also destroy() method called from service() method can do any deinitialization task etc but the servlet container will not unload the servlet, that can only be done by the lifecycle destroy() method.

Login to rate this answer.

Answered On : Jun 27th, 2007

Hi,Destroy method is a method where we can provide the actions (to free up the resources) to be performed while the servlet is getting unloaded. In general when a servlet is getting destroyed the servlet container calls this method and also does many other things. So if you want to unload a servlet you have to do all the things the servlet container does including calling the servlet method.When you directly call the destroy method from service method the method will be successfully called as you are calling the method from same object but you are not doing all the other things the servlet does to unload the servlet. So the servlet will not be unloaded but the destroy method will be called as any other non life cycle method (like display()).

Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions



twitter fb Linkedin GPlus RSS


Interview Question

 Ask Interview Question?


Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.