2 Replies Latest reply on Jan 26, 2004 7:25 PM by purdym

    is there a what to create a read/write application variable

    purdym

      using <env-entry> you can change a variable at deployment time, however after that, it is a static value. i you need to share a variable over an application, it doesnt help.

      is there a way to create a variable for an application (like an env-entry) which allows you to update the value.

      here is example code that explains what i need:
      ----------------------------------------------------------------
      long getNextKey() throws NamingException
      {
      long ret = -1;

      InitialContext jndiContext = new InitialContext();
      ret = ((Long)jndiContext.lookup("java:comp/env/lastContainerKey")).longValue();
      ret++;
      jndiContext.addToEnvironment("java:comp/env/lastContainerKey", new Long(ret));

      return ret;

      }//end getNextKey

      ---------------------------------------------------------------

        • 1. Re: is there a what to create a read/write application varia
          jamesstrachan

          You can't do this with an environment variable because it is not what they are there for.

          You need to use an entity bean that contains the last issued number, and can supply calling modules with the next number, as shown :-

          int getNextNumber() {
          storedNumber++;
          return storedNumber;
          }

          The method ejbStore() will be called immediately after this method executes, and should wite the changed value to somewhere safe.

          I would have attached, if I was allowed, a fuller example that copes properly with persistence to the database, and also allows for more than one sequence each identified by a key.

          Contact me directly on james.strachan@ntlworld.com if you would like that code.

          James


          • 2. Re: is there a what to create a read/write application varia
            purdym

            i did not want to use the database for this, because i planned on querying the database only once when jboss boots for the last id number and then keep it in a variable. but i looks like i will need a table in the db for variables such as these.

            thanx for your help,

            mpurdy