TomcatExpert

Disable caching/force reloading of JNDI resources

The idea was to provide multiple web applications running inside a Tomcat instance with configuration properties from config files located outside the WAR file of the applications. I'm currently trying to provide these configuration properties with a global naming resource (defined inside the server.xml) which is consumed by the said applications to keep the configuration container independent and to avoid direct file access from a web application. So far almost everything already works perfectly! Except that Tomcat obviously caches resources which are looked up via JNDI. This way I have to restart Tomcat every time the external config files changes because the web applications never access my ObjectFactory again after Tomcat has cached the result of the ObjectFactory. Is there any way to disable this behavior of Tomcat's JNDI resource management? Thanks in advance!

asked by

question

There is sort of a way to get this happen. It is not a cache, instead it is singleton or non singleton.

Take the default example that ships with Tomcat

 

<Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
 
With this configuration, getObjectInstance will only be called once. However, there is an attribute that can be set that will make sure that getObjectInstance is called every time a Context.lookup happens, it is singleton="false" 
 
<Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml"
              singleton="false"/>

Then you are able to decide when getObjectInstance returns a new object, or a cached object in your own code.

 

answer

answered by fhanik on January 7, 2013 04:55 PM

Filip Hanik is a Senior Software Engineer for the SpringSource Division of VMware, Inc. (NYSE: VMW) and a key participant in the company's Apache Tomcat initiatives. Filip brings 15 years of extensive experience in architecture, design and development of distributed application frameworks and containers and is recognized for his top-quality system development skills and continuous participation of Open Source development projects. Filip is an Apache Software Foundation member and a committer to the Apache Tomcat project where he is a leading authority on Tomcat clustering and a key contributor to the core of the platform. Filip has made contributions to software initiatives for Walmart.com, Sony Music, France Telecom and has held a variety of senior software engineering positions with technology companies in both the United States and Sweden. He received his education at Chalmers University of Technology in Gothenburg, Sweden where he majored in Computer Science and Computer Engineering.

Comments

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.