| Author |
Servlet destroy() method
|
Mansukhdeep Thind
Ranch Hand
Joined: Jul 27, 2010
Posts: 1153
|
|
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 ?
|
~ Mansukh
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12325
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
Mansukhdeep Thind
Ranch Hand
Joined: Jul 27, 2010
Posts: 1153
|
|
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?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
It's up to the servlet container to decide that.
|
 |
Mansukhdeep Thind
Ranch Hand
Joined: Jul 27, 2010
Posts: 1153
|
|
|
Thanks Paul. Will close this topic now.
|
 |
 |
|
|
subject: Servlet destroy() method
|
|
|