• 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

when the destroy() methid caled

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
when servlet destroy() is called in the life cycle and teh real time.
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 437
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The destroy() method is called after the service method is completed and is called before garbage collection
With regards,
Padma priya N.G.
 
naresh govindaswmay
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"mgnaresh mgnaresh",
you've already been warned here concerning your name. Please take some time to adjust it according to the Naming Policy.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 don't even know how to spell CIA. But this tiny ad does:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic