Results 1 to 4 of 4

Thread: Is it possible to call destroy() method within init() Method?

  1. #1
    Join Date
    Nov 2009
    Posts
    862

    Is it possible to call destroy() method within init() Method?

    Hi Friends,

    I am IT student, I want a solution over confusion of advanced java. I have basic idea about the servlet. As we know that servlet life cycle starts from the init() method and life cycle can be ended using the destroy() method. But my question is that, Is it possible to call destroy() method within init() Method? and if we call destroy() method what will happen?
    Please let me know solution to sort-out this confusion regarding the destroy() method.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Is it possible to call destroy() method within init() Method?

    Hi,

    Basically init() method essential to open the connection for the servlets and on other hand destroy() method is used to close the different connection which is initialized by the init() method. In servlets of the advanced java it is possible to call destroy() method within init() method. But difference is that if you executes the java program, the body of the destroy() method will execute first, then body of the init() method will execute.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Is it possible to call destroy() method within init() Method?

    Hi,

    Following are some possibilities with destroy() method:
    *. If you invoke default method of the destroy() within init() method, it won't affect with functioning of the init().
    *. If you invoke destroy() method within service() method, It also won't affect with functioning of theservice() method.
    *. If you try to override destroy() method, It doesn't affect these init() method.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Is it possible to call destroy() method within init() Method?

    Why not? you are able to invoke the destroy() method of the java into the java init() method. In below example I included the destroy() method immediately after the calling of the init() method. Even though it didn't affect the init() calling:

    public class TestServletDemo Extends HttpServlet {


    public void init(ServletConfig cnfig)throws ServletException{
    super.init(cnfig);
    destroy();
    }

    void doGet(HttpServletRequest req1, HttpServletResponse respn)
    throws ServletException, IOException {

    System.out.println("Welcome in servlet.");
    }

    }

Similar Threads

  1. Method overriding versus method hiding in C#
    By ^MALARVIZHI^ in forum Software Development
    Replies: 4
    Last Post: 25-12-2010, 06:25 AM
  2. How can I call VBA method dynamically?
    By opaper in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 09:25 AM
  3. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 08:20 AM
  4. Java: How can I call one method in another method?
    By biohazard 76 in forum Software Development
    Replies: 3
    Last Post: 16-07-2009, 07:12 PM
  5. Method call of another Project
    By Mahendra varma in forum Windows Software
    Replies: 2
    Last Post: 22-04-2009, 03:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,570,822.71973 seconds with 17 queries