Dynamic Properties Loading in J2EE Application


General J2EE: Dynamic Properties Loading in J2EE Application

  1. Dynamic Properties Loading in J2EE Application (4 messages)

    Hi all,

       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 !
  2. 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.
  3. 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.
  4. Hi Kris,

       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 ?

    Best Regards
  5. 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.