File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet destroy() method

 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 1
  • Mark post as helpful
  • send pies
  • 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: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Paul Clapham
Sheriff
Pie
Posts: 20171
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's up to the servlet container to decide that.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul. Will close this topic now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic