• 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

Servlet destroy() method

 
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have some queries regarding the destroy() method of the servlet life cycle:

a) Who calls the destroy() method during the final phase of the servlet life cycle? Does the container do it like it does the initialization of the servlet class when it is first loaded ? Or is it handled internally in some other way?

b ) When is actually a servlet class destroyed and available for GC ?

 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a) only the servlet container should call destroy as part of the life cycle.
It is up to the servlet programmer to code the destroy method to clean up any resources used. Be careful, check for null ref before trying to - for example - close database connections.
b) 1. say servlet class instance, not servlet class - using the right words helps understanding
....2. actual cleanup is up to the servlet container and jvm
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:a) only the servlet container should call destroy as part of the life cycle.
It is up to the servlet programmer to code the destroy method to clean up any resources used. Be careful, check for null ref before trying to - for example - close database connections.
b) 1. say servlet class instance, not servlet class - using the right words helps understanding
....2. actual cleanup is up to the servlet container and jvm



OK. So, as far as the init() and destroy() methods are concerned, it is up to the servlet container and the JVM do decide when to initialize and destroy the servlet instance. Correct?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's up to the servlet container to decide that.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1164
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul. Will close this topic now.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic