3 Replies Latest reply on Sep 21, 2006 10:53 AM by jaikiran pai

    how can i store config file

    Kiran Kumar Newbie

      Hi,

      I need to read config file during ejb creation time and store it in memory.
      This ejb is simple stateless session bean. How can I achive it.

      I mean, I dont want read the config file for every request.

        • 1. Re: how can i store config file
          jaikiran pai Master

          Have a singleton utility class which will read the file once when it is instantiated. Invoke this singleton utility class from your EJB whenever you want the values for your properties

          • 2. Re: how can i store config file
            Nagesh Gummadivalli Newbie

            Thanks, I am thinking of having a Config Mgr as singleton. But not sure where to put the logic of invoking this ConfigMgr (from ejbCreate or setSessionContext())

            "jaikiran" wrote:
            Have a singleton utility class which will read the file once when it is instantiated. Invoke this singleton utility class from your EJB whenever you want the values for your properties


            • 3. Re: how can i store config file
              jaikiran pai Master

              You need not write the code of instantiating the singleton in the ejbCreate or any other specific method. You can do something similar to:

              MyEJB implements SessionBean {
              
               public void someMethod() {
              
               //do some logic
               .....
               //at this point, i need the value for a property. So do the following
               ConfigMgr.getInstance().getPropertyValue("someProperty");
              
               }
              
              }
              
              ConfigMgr {
              
              
               private static ConfigMgr configMgr;
              
               private Properties properties;
              
               private ConfigMgr() {
              
               //load the properties file
               properties = someCodeToLoadPropertiesFile();
               }
               public synchronized static getInstance() {
              
               if (configMgr == null) {
               configMgr = new ConfigMgr();
               }
               return configMgr;
               }
              
              
              }