I’ve been attempting to pull hard-coded configuration data from a Tomcat web-app which I’m working on, into JNDI (web.xml) to make the app more configurable. Instead of continuously doing lookups into the InitialContext, I’m caching the lookups and the InitialContext using a singleton.
Of course, when I stop and start the application, the static instance of my singleton remains alive — therefore, the cache doesn’t get “refreshed”. My question is dual — I’m isolating this singleton to a single web application — are there any unforeseen effects in Tomcat [I’ve read that singleton’s & tomcat don’t mix]? And what is the easiest way to clear the singleton instance when the application is stopped (I was thinking of writing a separate ServerContextListener which would clear the instance).
(Note: I apologize if I used the terminology incorrectly — please correct — this is my first foray into programming with Tomcat)
Ok, so you implemented a Service Locator with a cache, that [is|was] a common practice for the web tier. Here is an example.
Hmm… unless you are deploying your singleton in the Common class loader (
$CATALINA_HOME/lib) it shouldn’t. You’re not doing this, right?Nothing I’m aware of.
Deploy your singleton in the webapp class loader (i.e. in
/WEB-INF/classesor/WEB-INF/lib) and undeploy the application as suggested.