1 Reply Latest reply on Sep 5, 2008 11:52 AM by peterj

    Single instance of utility per ejb service

    ashitre

      Hi,
      I have a utility class placed in shared lib folder of profile.
      Each ejb instance will create one instance of this utility class, so one instance per ejb. But I want to have only one utility instace across one type of ejb instances in the jboss.

      For example there are 2 ejb services ejb1 and ejb2. ejb1 has 2 instances ejb1.1 and ejb1.2 and ejb2 has 2 instances ejb2.1 and ejb2.2. So the requirement is ejb1.1 and ejb1.2 should share single instance of utility and similarly ejb2.1 and ejb2.2 should share another instance of utility.

      Does anybody have any idea to resolve the issue ?

      Thanks in advance.

        • 1. Re: Single instance of utility per ejb service
          peterj

          Try using a factory to create the instance, where each EJB gives an identifier and the factory returns an instance based on that identifier. Sort of what the logging frameworks do when you lookup a logger.

          Another alternative would be to place your shared JAR file into an EAR and use an isolated classloader. For example, EAR1 contains utility.jar and ejb1.jar, EAR2 contains utility.jar and ejb2.jar. And make the utility class a singleton.

          There are probably other ways, but these two seem most appropriate.