This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Can i use  finalize method instead of destroy in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can i use  finalize method instead of destroy in servlets" Watch "Can i use  finalize method instead of destroy in servlets" New topic
Author

Can i use finalize method instead of destroy in servlets

Aadi Jampani
Greenhorn

Joined: Jul 04, 2005
Posts: 1
Hi Everybody,

Can any please answer me for the fallowing questions.

1.can i use finalize method insted of destroy method?
2.In which instances the destroy method ll be called?

Thnx in advance.....
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
Nothing prevents you from writing a finalize() in a servlet class.
The preferred approach to cleaning up when a servlet goes out of service is the destroy method - see the servlet API.
Anybody seriously interested in servlets should have a copy of the API. You can download it for free from this Sun site.
The idea is that the servlet container will call your servlet's destroy method when the servlet instance is about to be removed - possibly as part of orderly shutdown of the server, possibly for some other reason. Since you are NOT guaranteed that GC will run during server shutdown, finalize is a bad choice.
Bill
 
jQuery in Action, 2nd edition
 
subject: Can i use finalize method instead of destroy in servlets
 
Similar Threads
Reclaiming memory in java without using garbage collector........
frnds come up with solution
finalize() and destroy()
JSP FAQ
difference between destroy() & finalize()