tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkv <>
Subject Singletons in Tomcat(6.0)
Date Tue, 01 Dec 2009 13:01:34 GMT


Is using singleton patterns in Tomcat (in servlets programming and deploying
them in tomcat) a really bad idea?? I came accross many forum posts and
wikis that warn about of OOM errors. One really useful post is  and this is really worth taking a
We are having a web application and have four or five singleton patterns,
they are really necessary as singletons patterns, such as Xml parsers and
Applications properties reader. I have some questions when they say. "server
being unable to reclaim the space for the entire webapp class loader". 

1) Will I be getting OOM errors only when I redeploy a war file (with
singleton patterns) several times without re-starting my Tomcat? Or I will
be getting the OOM errors even if I didnot redeploy the war file and the
server crashes after some days??

2) I dont think we can GC a conventional singleton pattern by using a
ServletContextListener, as the private instance variable is hard coded and
we cannot access it from outside(and set it to null) as its never visible to
the outside world unless we try using reflection??

The link that I posted has a reference to apache.commons DiscoverSingleton
for Singleton patterns. I have not tried that in my web applications. Will
that help me?? instead of using the conventional singleton pattern??

Any suggestion is highly appreciated

Thanks in advance
View this message in context:
Sent from the Tomcat - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message