aspose file tools*
The moose likes Servlets and the fly likes init and destroy method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "init and destroy method" Watch "init and destroy method" New topic
Author

init and destroy method

felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
Can i call destroy method explicity from init method.
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
I have never tried it, but I suspect an exception will be thrown since the servlet would not successfully initialize.


SCJP, SCWCD, SCBCD, IBM CSD WebSphere v5, <br />A+, MCP 2000 and 2000 server, CST, and few incompleted certification tracks.<br /> <br />Ivory Coast<br /> <br />Analyze your web Request/Response @ <a href="http://webtools.servehttp.com" target="_blank" rel="nofollow">http://webtools.servehttp.com</a> down for a while...
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
it's just a method so you can call it.
The only significance of the name destroy is that, given the correct signature, it will also be called during garbage collection.


42
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
It's actually not called during garbage collection, but during server shutdown -- but other than that, Jeroen's absolutely right -- it's just another method.

Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Actually, an execption will be thrown as I suspected:



It is a method, but not any method.
felix thomas
Ranch Hand

Joined: Jun 10, 2001
Posts: 89
This is the code and i don't get an exception.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Inittesting extends HttpServlet
{
PrintWriter out=null;


public void init(ServletConfig s) throws ServletException
{

super.init(s);
System.out.println("in init before");
super.destroy();
System.out.println("in init");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{


try
{
//common instantiations required for the document login to build up
out=response.getWriter();

response.setContentType("text/html");

//super.destroy();
out.println("servlet now 33 ");

}catch(Exception e)
{
out.println("exception :"+e);

}
}



}
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
This does on Websphere:

Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Also, Thomas, can you show your initialization output?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
yah, was confused with finalize()...
Too much reading about garbage collectors for my SCJP study lately
Brahim Bakayoko
Ranch Hand

Joined: Aug 29, 2003
Posts: 155
Originally posted by Jeroen Wenting:
yah, was confused with finalize()...
Too much reading about garbage collectors for my SCJP study lately


Maybe a good time for a cold beer (an extra cold Guinness stout for me) and some good sleep.
Been there...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init and destroy method