aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes explicit call to destroy() ....possible??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "explicit call to destroy() ....possible???" Watch "explicit call to destroy() ....possible???" New topic
Author

explicit call to destroy() ....possible???

Sakthi Kani
Ranch Hand

Joined: Mar 29, 2005
Posts: 98
Hi

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



public class Test extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
PrintWriter out=res.getWriter();
out.println("Hello");
destroy();
out.println("World");
}

};


output:
Hello
World

How 'World' is getting printed after the detroy() method called?
Please explain me.

Thanks in advance.


" Don't be afraid of pressure. Remember that pressure is what turns a lump of coal into a diamond... " <br /> <br />Thanks & Regards...<br />Sakthi<br />SCJP1.4, OCA
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
You can find it in servletcollections link found in my signature. check out archives section.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580

How 'World' is getting printed after the detroy() method called?
Please explain me.


All of a servlet's service methods should be complete when a servlet is removed. The server tries to ensure this by calling the destroy method only after all service requests have returned or after a server-specific grace period, whichever comes first. If your servlet has operations that take a long time to run (that is, operations that may run longer than the server's grace period), the operations could still be running when destroy is called.
Sakthi Kani
Ranch Hand

Joined: Mar 29, 2005
Posts: 98
I am clear now.
Thanks your reply.
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 950
Hi,

All of a servlet's service methods should be complete when a servlet is removed. The server tries to ensure this by calling the destroy method only after all service requests have returned or after a server-specific grace period, whichever comes first. If your servlet has operations that take a long time to run (that is, operations that may run longer than the server's grace period), the operations could still be running when destroy is called.


I think this is true, when the container is going to destroy the servlet.

But in the above example, we are calling the destroy() method explcitly. This will not remove/or destroy the servlet instance at all. This is the normal call like any other method called by the user on the servlet. So, it simply run the code in destroy() method and resume the execution of the service method. Running of destroy() method does not means that the servlet is no longer available. In the servlet life-cycle the servlet call the destroy() method to clean any resources before removeing the servlet.

Think it help you.

Thanks


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Hong Anderson
Ranch Hand

Joined: Jul 05, 2005
Posts: 1936
I agree with Narendra Dhande.
The destroy() is a callback method that will be called when servlet instance was destroyed by container.
If you call destroy() it's just a normal method call.


SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJP 5.0, SCEA 5, SCBCD 5; OCUP - Fundamental, Intermediate and Advanced; IBM Certified Solution Designer - OOAD, vUML 2; SpringSource Certified Spring Professional
Sakthi Kani
Ranch Hand

Joined: Mar 29, 2005
Posts: 98
Thank you all.
got the exact point now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: explicit call to destroy() ....possible???