2 Replies Latest reply on Aug 6, 2013 1:57 PM by Avor Nadal

    Where to store a singleton that must be available to every EJB?

    Avor Nadal Newbie

      Hello:

      I need a place to store a single instance that must be available to every EJB. In other words, a singleton.

       

      In the past, I've been using the well-known singleton strategy described in the book "Design Patterns" by GoF, which consists in using the static attribute of a subclass to hold a single instance of the desired class. However, I've been convinced to abandon this idea (because of reasons that are beside the point) and am looking for an alternative.

       

      Because the information contained by such instance is restricted to the EJB module, I can't pass this object as an argument from the client side. So I need a common place to store it.

       

      I want something equivalent to the methods getAttribute (), setAttribute () and removeAttribute () of the class javax.servlet.ServletContext, but for EJB

       

      So my questions are:

       

      • Is there a standard place, accessible by every module, to store arbitrary data in EJB? Just as in javax.servlet.ServletContext.
      • If there isn't, Are the Singleton Session Beans the way to solve this problem?
      • In EJB 3.0, which Singleton Session Beans don't exist in, Would you recommend tricking the server to limit the number of instances of an EJB to one?

       


      Thank you very much for your help.