• 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

Destroy() method in the life cycle of the servlet

 
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,
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.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Padma priya Gururajan
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,
Thanks.
With regards,
Padma priya N.G.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


To the best of my knowledge its not the container, its for the servlet developer to free any held resources in destroy method.
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Amol!



Thanks,
 
Durga Prasad Vuyyuru
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Padma priya Gururajan
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 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
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,
yes.resources are released by develpoer only...
regards
mgnaresh
 
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,
Your name does not fit with the ranch's Naming Policy. Could you please read it and change your name accordingly ? Thank you
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Padma priya Gururajan
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 Raghavan,
It clears my doubt.
Padma priya N.G.
 
Squanch that. And squanch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic