2 Replies Latest reply on Oct 31, 2008 3:41 PM by hjhjr4

    EJB3 stateless session bean local proxy threading

    hjhjr4

      Can an instance of EJB3 stateless session bean local proxy received from
      context.lookup()
      be used from multiple threads?

      For example, I have a utility function that can be called from multiple threads and that has to access stateless session bean.
      Should it be implemented like this:

      1.
      public class Util {
      private static ConfigurationEjb conf = context.lookup(...)

      public static func() {
      conf.getValue()........
      }
      }

      or like this:

      2.
      public class Util {
      public static func() {
      ConfigurationEjb conf = context.lookup(...) //is this expensive???
      conf.getValue()........
      }
      }

        • 1. Re: EJB3 stateless session bean local proxy threading
          alrubinger

          JBoss EJB3 provides Thread-safe Proxies from JNDI. This may not be true in other implementations.

          "EJB 3.0 Core Specification 4.7.11: Non-Reentrant Instances" wrote:
          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 javax.ejb.ConcurrentAccessException to the second client[24]. If the EJB 2.1 client view is used, 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.[25]

          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.

          One implication of this rule is that an application cannot make loopback calls to a session bean instance.


          For SLSB, invocation may occur concurrently, though separate underlying bean instances will be used (as we pull only unused instances from a Pool.

          For SFSB, invocation will block until the requisite session is available/unused. You may override this behaviour using the @SerializedConcurrentAccess annotation.

          "hjhjr4" wrote:
          ConfigurationEjb conf = context.lookup(...) //is this expensive???


          Yes, cache your entries from JNDI for SLSB, and only perform a lookup on SFSB when you need a *new* session.

          S,
          ALR

          • 2. Re: EJB3 stateless session bean local proxy threading
            hjhjr4

            Thanks for this explanation!