• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

What is the significance of destroy() method in servlets lifecycle ?

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the significance of destroy() method in servlets lifecycle ?
When there is a finalise() method with every java object.
 
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rohan,

I would say that when the container calls the servlet's destroy method to make the servlet object elligible for garbage collection be it automatic through the scheduler or through finalize().

Regards,
Darya
 
Rohan Kayan
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
But it is still not clear , to make any object eligible for Garbage Collection we need only to set all the live reference of that object equal to null .Then what is the use of destroy method?


Rohan
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question to you Rohan ,

who do you think calls the servlet's destroy() method ? And why ?

Regards,
Darya
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

As per the servlet specs, the destroy method must be called by the container when a servlet is removed from service. If any resources are acquired in the init() method, this is the method where where we should release them, the typical example being database connections.

The finalize method is called before an object is garbage collected. But unlike the destroy method, there is no guarantee that this method will be called before garbage collection.

- Gouri
 
Rohan Kayan
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for Reply , Now I got that .
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rohan,

to answer my question to you for you . The Container is doing that for you. The same way like the Container creates the servlet for you it destroys it for you.

The Container is doing the whole lifecycle of a servlet from life to death.

So why do you want to reinvent the wheel

Regards,
Darya
 
Rohan Kayan
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Darya Akbari:
Rohan,

to answer my question to you for you . The Container is doing that for you. The same way like the Container creates the servlet for you it destroys it for you.

The Container is doing the whole lifecycle of a servlet from life to death.

So why do you want to reinvent the wheel

Regards,



Darya


Hi Darya Akbari ,
I don't want to reinvent the wheel . I just wanna know is there any significance of having a separate method when there is already a finalise method for every objects . But I got the reason behind this , as finalise is called by GC and even then its execution is not confirmed . So container needed another method method called destroy for all the cleaning job

.


Rohan
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rohan,

I think you still didn't get it . At least your last explanation seems to me that way (forgive me when I am wrong ).

The destroy method is called by the container NOT BECAUSE THE GC DIDN'T DO ITS JOB OR BECAUSE TO KILL THE LAST SERVLET REMNANTS FROM MEMORY but because the container decides to do so in case of an container shut down for example.

Whether and when the finalize or GC works is under the control of your JVM.
The container just make his servlet objects (and all related objects) available (elligible) for GC without concern of whether your JVM start GC or not.

Regards,
Darya
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic