• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

init and destroy method

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can i call destroy method explicity from init method.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This does on Websphere:

 
Brahim Bakayoko
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic