2 Replies Latest reply on Sep 19, 2006 11:54 PM by Victor Kasenda

    EJB 2.0 - SLSB - Lifecycle/class member/thread safe question

    Mike Reamy Newbie

      I know that SLSB should not have class member variables. Can someone verify that the following thinking is correct:

      A client obtains an instance of the SLSB.
      The client executes a method in the SLSB.
      After execution the instance is returned to the pool.

      Question:
      Can a single instance be obtained by multiple clients at the same time?

      We had an RMI factory service which returned a new instance of a class for each user. This new instance had member variables. We switched over to SLSBs, but when it was switched over the member variables were not moved into the methods. There is a call at the begining of every method that initializes these methods. We are planning on moving all of the class members into the method, but in the short term is it safe to assume that only one instance will be executed per user?

        • 1. Re: EJB 2.0 - SLSB - Lifecycle/class member/thread safe ques
          Mike Reamy Newbie

          Correction, the class member variables in the SLSB are reinitialized in every method.

          • 2. Re: EJB 2.0 - SLSB - Lifecycle/class member/thread safe ques
            Victor Kasenda Newbie

            According to EJB Spec, Session beans are non-reentrant i.e. one instance can only service one client at a time. This should be true for all EJB containers, including JBoss.


            Quoting the 2.0 spec:

            Non-reentrant instances
            The container must ensure that only one thread can be executing an instance at any time. If a client
            request arrives for an instance while the instance is executing another request, the container may throw
            the java.rmi.RemoteException to the second request if the client is a remote client, or the
            javax.ejb.EJBException if the client is a local client.[6]
            Note that a session object is intended to support only a single client. Therefore, it would be an
            application error if two clients attempted to invoke the same session object.