Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links


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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 10-12-2009
Level8's Avatar
Member
 
Join Date: Nov 2009
Posts: 871
Is it possible to call destroy() method within init() Method?

Sponsored Links
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.

Reply With Quote
  #2  
Old 10-12-2009
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,943
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.
Reply With Quote
  #3  
Old 10-12-2009
Member
 
Join Date: May 2008
Posts: 2,000
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.
Reply With Quote
  #4  
Old 10-12-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,989
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:

Quote:
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.");
}

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Is it possible to call destroy() method within init() Method?"
Thread Thread Starter Forum Replies Last Post
Method overriding versus method hiding in C# ^MALARVIZHI^ Software Development 4 25-12-2010 05:25 AM
How can I call VBA method dynamically? opaper Software Development 5 28-01-2010 08:25 AM
What is method overriding and method overloading in java beelow Software Development 3 17-11-2009 07:20 AM
Java: How can I call one method in another method? biohazard 76 Software Development 3 16-07-2009 07:12 PM
Method call of another Project Mahendra varma Windows Software 2 22-04-2009 03:40 PM


All times are GMT +5.5. The time now is 08:15 PM.