Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when is destroy called

 
timothy passcal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when is a servlets destroy method called?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the container wants to remove the instance from the memory. There is no particluar condition which needs to occur for the container to act so.
 
timothy passcal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lets say that i have connections to database, mainframes, the moon etc... open.. do they remain open if i do not close them in the destroy method or do they remain in limbo until the jvm is turned off.
and when does the container unload a servlet, is there a reason why it should unload the servlet. is there any way, say on tomcat that i could go and look this info up..
thanks for the quick reply..
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From spec
The servlet container is not required to keep a servlet loaded for any particular
period of time. A servlet instance may be kept active in a servlet container for a
period of milliseconds, for the lifetime of the servlet container (which could be a
number of days, months, or years), or any amount of time in between.
When the servlet container determines that a servlet should be removed from
service, it calls the destroy method of the Servlet interface to allow the servlet to
release any resources it is using and save any persistent state. For example, the
container may do this when it wants to conserve memory resources, or when it is
being shut down.
Before the servlet container calls the destroy method, it must allow any
threads that are currently running in the service method


You will close all resources in the destryoy method (in case you have not yet closed them) else they will be lost in memory until the garbage collection occurs.
 
timothy passcal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks good reply.. dont know y i forgot garbage collection
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic