destroy() method in service()

can we call destroy() in service() method. if we call destroy() before any business logic what happens to the request of the client.

[139 byte] By [rajaramesh25a] at [2007-11-27 11:17:15]
# 1

As I understand it, when the last person logged into your application goes away (nativigates away from your web site), the servlet will eventually time out. When it does, it calls destroy() automatically (if you defined it) just before it dies. In that routine, you should clean up any resources that you had open for all users to use). You can call it programmatically at any time, but I dont see why you would want to.

George123a at 2007-7-29 14:23:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Calling destroy() inside serivce() can affect nothing, because the main job for destroy() is to excute a defined code at the end of the servlet lifecycle, and not the opposite, i mean calling destroy() doesn't finish the servlet..

check this servlet code it might help...

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.*;

import javax.servlet.http.*;

public class Servlet extends HttpServlet {

private static final String CONTENT_TYPE = "text/html; charset=windows-1252";

public void init(ServletConfig config) throws ServletException {

super.init(config);

}

public void doPost(HttpServletRequest request,

HttpServletResponse response) throws ServletException,IOException {

destroy();

response.setContentType(CONTENT_TYPE);

PrintWriter out = response.getWriter();

out.println("<html>");

out.println("<head><title>Servlet</title></head>");

out.println("<body>");

out.println("

The servlet has received a POST. This is the reply.

");

out.println("</body></html>");

out.close();

}

public void destroy(){

System.out.println("Inside Destroy");

}

}

now in this code destroy() is called in the begining of service(). and the statement "Inside Destroy" is printed, and the then service() continue its work normally...

hope i helped (^_^);

QussayNajjara at 2007-7-29 14:23:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...