• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

init and destroy method

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i call destroy method explicity from init method.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never tried it, but I suspect an exception will be thrown since the servlet would not successfully initialize.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Brahim Bakayoko
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, an execption will be thrown as I suspected:



It is a method, but not any method.
 
felix thomas
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This does on Websphere:

 
Brahim Bakayoko
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, Thomas, can you show your initialization output?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yah, was confused with finalize()...
Too much reading about garbage collectors for my SCJP study lately
 
Brahim Bakayoko
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic