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

How are ServletContext attributes GC'd

 
nico dotti
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I do:


What should I expect from the container/JVM concerning the life of this object? If I need it for the life of the application (server start/stop), will this work?
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As you have mentioned ServletContext attribute is available to all the resources in the web application.
So I guess it should survive till the webapplication is up and running.
It may be gc'ed when you explicitly set value of the attribute to null.
I think this is a interesting scenario to think upon.

regds,
Amit
 
nico dotti
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just ran my application and the logger object seemed to be available to all the code (a Servlet, POJO, and a JSP). So I guess as you mention it won't get GC'd unless I explicitly made it null. So I wonder what object is always referencing it? ServletContext I suppose? That's what I'd figure intuitively at least LOL
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes obviously whatever you put/get with respect to ServletContext, they are expected to be alive till the time either the webapplication or the server is down!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic