On 5/3/06, Darryl Miles <[EMAIL PROTECTED]> wrote:

Maybe a useful URL to help address this matter when it bites, look for
the java code in the forum thread:
http://forum.hibernate.org/viewtopic.php?t=935948&start=150

Something to put at the end of your
javax.servlet.ServletContextListener#contextDestroyed(ServletContextEvent).


OMG! :-)
I think it's easier to let all your singletons to extend an abstract
MySingleton class, which registers itself in a (singleton)
ServletContextListener and calls reset() (or whatever you name it) in
contextDestroyed :-)
But the code itself is funny...


Abstracting your Singletons behind something else (maybe something as
saft as Map) which has simple lifecycle management hooks on all
contained objects would allow during context undeploy for the shutdown
to be called on the lifecycle.

Exactly :-)
Or keep the references not in singletons itself but in the factories.


Even I am not that zealous with caution to implement and use it for
everyday code.


The same problem can exist for ThreadLocal data (which a common pattern
hibernate uses), if you don't gaurd your code usage so that as you
cleanup from the servlet/filter you null out the ThreadLocal you may
have setup.

Darryl


regards
Leon

Peter Crowther wrote:
>> From: Leon Rosenberg [mailto:[EMAIL PROTECTED]
>> Could you explain it a bit more? What's the difference whether I have
>> 10 instances of the same class or just one for reloading?
>
> In a Singleton:
>
> - the class holds a reference to the classloader;
>
> - the class holds a reference to the singleton instance;
>
> - the instance holds a reference to the class.
>
> My understanding is that classes cannot be GCed unless they have no
> instances, and classloaders are (obviously) not collected until they
> have no references from classes.  So singletons leave classes lying
> around in your JVM.  More annoyingly, classes always occupy PermGen
> space, so this junk class is now eating up precious space in PermGen -
> hence the possibility of an OOME if you reload your webapp too many
> times.  The solution is to implement appropriate listeners to make sure
> the instance is not referenced by the class before the webapp is
> unloaded.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to