This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes when the destroy() methid caled Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "when the destroy() methid caled" Watch "when the destroy() methid caled" New topic
Author

when the destroy() methid caled

naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
hi,
when servlet destroy() is called in the life cycle and teh real time.


Thanks and Regards<br />Naresh govindaswamy
khushhal yadav
Ranch Hand

Joined: Jun 20, 2007
Posts: 242

Just before your servlet instance is garbage collected.
Like finalize() methods for objects of your java classes, you can't gaurantee when it will be exactly called.

Regards,
Khushhal


rgrds,
Khushhal
anil kumar
Ranch Hand

Joined: Feb 23, 2007
Posts: 447
Hi

destroy() will be called when ever we remove the servlet instance from the service.

After completion of the destroy() method,the object is eligible for garbage collection.


Thanks

Anil Kumar
Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 434
Hi,
The destroy() method is called after the service method is completed and is called before garbage collection
With regards,
Padma priya N.G.


Padma priya N.G.
Be the change you want to be - Mahatma Gandhi
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
hi,
I have attached the sample code here please check it in what situation the servlet destroy() is called..

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class LifeCycle extends HttpServlet
{
public void init(ServletConfig cfg)
{
System.out.println("Inside the servlet init method");
}
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
System.out.println("Inside the sevice method ");
HttpSession session=request.getSession();
System.out.println("the session is created");
session.invalidate();
System.out.println("the session is destroyed.......");
}
public void destroy()
{
System.out.println("inside the destroy....");
}

};

regards
naresh
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

"mgnaresh mgnaresh",
you've already been warned here concerning your name. Please take some time to adjust it according to the Naming Policy.


[My Blog]
All roads lead to JavaRanch
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Anil said:
destroy() will be called when ever we remove the servlet instance from the service.


We dont remove the servlet instance, its upto the container to decide that.

padmapriyagururajan said:
The destroy() method is called after the service method is completed and is called before garbage collection


The spec says this:

Before the servlet container calls the destroy method, it must allow any
threads that are currently running in the service method of the servlet to complete
execution, or exceed a server-defined time limit.


Naresh as the spec says, if all the threads running in service are done and if the container wishes to remove the instance then destroy is called.
You cannot force the container to do it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when the destroy() methid caled
 
Similar Threads
WA #1.....word association
why is destroy() ??when there is Garbage Collection in java??
destroy( ) method
when is destroy called
when destroy method will call