aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Destroy() method in the life cycle of the servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Destroy() method in the life cycle of the servlet" Watch "Destroy() method in the life cycle of the servlet" New topic
Author

Destroy() method in the life cycle of the servlet

Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 430
Hi,
When the destroy() method is called at the end of the life cycle of the servlet , is any of the resources held by the container released?
Source: Whizlabs
With regards,
Padma priya N.G.


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

Joined: Mar 22, 2007
Posts: 102
after service() method , the destroy method is called...

it is not like if we have... some resources to be realeased only... then only it has to be called...

if you have resources held or not it is called as it is.. a part of "Servlet LIFE CYCLE"

hope i made it clear.
Durga Prasad Vuyyuru
Greenhorn

Joined: Aug 06, 2007
Posts: 25
Hi priya,

When the destroy() method is called at the end of the life cycle of the servlet ,all the resources held by the container will be released


V.DURGA PRASAD
Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 430
Hi,
Thanks.
With regards,
Padma priya N.G.
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218


To the best of my knowledge its not the container, its for the servlet developer to free any held resources in destroy method.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
I agree with Amol!



Thanks,


cmbhatt
Durga Prasad Vuyyuru
Greenhorn

Joined: Aug 06, 2007
Posts: 25
Hi Amol,


To the best of my knowledge its not the container, its for the servlet developer to free any held resources in destroy method.

That is when the destroy method is called, the resources which was hold by the developer will be released.Is it true?(Just I am confused whether the resources held by the container or servlet developer will be released when the destroy() is called.)
Thank you,
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Description in javadocs:
Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet.

This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads) and make sure that any persistent state is synchronized with the servlet's current state in memory.


If you read the second paragraph it says that it gives a chance to servlet. So its the servlet developer's responsibility to close any open connections, handles etc in the destroy method.
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
hai
though the servlet container is called the servlet destroy() at the end of life cycle.you should hard cade it what are all the resources should be released.This is the one way to accept and another way is the REQUEST and RESPONSE object is killed at the end of the destroy() so all resources is released autometically....


Thanks and Regards<br />Naresh govindaswamy
Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 430
Hi Naresh,
Do you mean to say that the destroy() method releases the resources and not the developer. Am I right?
With regards,
Padma priya N.G.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
Originally posted by mgnaresh mgnaresh:
This is the one way to accept and another way is the REQUEST and RESPONSE object is killed at the end of the destroy() so all resources is released autometically....

The destroy method is called when there is no active request, so request and response objects are not relevant to it.

Originally posted by padmapriyagururajan priya:
Do you mean to say that the destroy() method releases the resources and not the developer.

The default destroy method (which does nothing) can be overridden by the developer in order to perform any cleanup necessary. Nothing happens in it unless the developer codes it first; it's just that the method is called automatically by the container, like the init method is called before the first request.


Ping & DNS - updated with new look and Ping home screen widget
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
hi,
yes.resources are released by develpoer only...
regards
mgnaresh
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

mgnaresh mgnaresh,
Your name does not fit with the ranch's Naming Policy. Could you please read it and change your name accordingly ? Thank you


[My Blog]
All roads lead to JavaRanch
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Originally posted by padmapriyagururajan priya:
Hi Naresh,
Do you mean to say that the destroy() method releases the resources and not the developer. Am I right?


destroy() method releases means the "code written by the developer inside the destroy() method" is executed thereby it seems like the destroy method releases the resources.

As Ulf said, its given a chance to the servlet if required it can have an overridden destroy() method to have its own piece of code which can take care of releasing the resources.

So, its purely upto the programmer/developer of the Servlet who is overriding the destroy() method.

Does that clear your doubt?


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Padma priya Gururajan
Ranch Hand

Joined: Oct 05, 2006
Posts: 430
Hi Raghavan,
It clears my doubt.
Padma priya N.G.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Destroy() method in the life cycle of the servlet
 
Similar Threads
init(ServletConfig)
when the destroy() methid caled
why lifecycle method required ?
Question related to Servlet Life cycle
how many times init() method gets called