- Posted by: Sean Tan
- Posted on: December 08 2004 20:38 EST
I am using some .properties and .xml files to configure some values in my J2EE application which consider for EJB and Web apps. These files are specified in the classpath.
What would be the best approach to have dynamic loading of the values in the properties/xml when they are changed, without restarting the server ?
1) Loading the properties file in each method call that needs it. However this iccurs extra IO overhead.
2) This article suggested using a timer to track the file timestamp and reload the values when the timestamp changed.
However, since I am running a J2EE application, I think threading or timers are out of the question.
Anyone has a better alternative ?
Thank you !
- Dynamic Properties Loading in J2EE Application by Sergey Pomytkin on December 09 2004 09:41 EST
- Dynamic Properties Loading in J2EE Application by Kris Huggins on December 09 2004 18:39 EST
Depends on details of your problem… Often exposing configuration API could be good solution. Just put EJB/SOAP facade on top of you load method.
Create a class that represents this configuration and expose it throug a singleton. Make the function that reads in the configuration public if it's not. Create an EJB that will get the singleton and call the function that realods the configuration. Program all of the objects that use the configuration to read from the singleton each time it uses it (e.g. don't cache the values gotten from your configuration in the configuration consumer).
There may be issues if you are using clustering. If you are using clustering then your EJB should put the configuation into JNDI and the configuration consumer would use JNDI.
Thanks for the reply. Do you mean that the objects that uses the configuration to invoke the EJB which will in turn reloads the configuration from the properties file and return the values ?
Wouldn't this incur IO overhead each time the properties is reloaded, on top of the EJB call ? What difference would it compared with reloading the properties directly in the singleton instead of having the EJB ?
Sorry, I didn't finish my thought...
The EJB that loads the configuration would need to be called explicitly by a client. This client would be a stand alone app that you would write whose only job is to invoke this EJB which tells the singleton to reload its properties. You would run the client whenever you redeploy the properties file.
The consumers of these properties would just need to get the properties from the singleton, however, this would have to be thread safe.