[jboss-user] [JBoss Seam] - Re: conceptual question about concurrency

wschwendt do-not-reply at jboss.com
Fri Sep 14 07:18:50 EDT 2007


"matt.drees" wrote : Thanks for answering!
  | 
  | So, now I have two questions.  
  | 
  | 1.
  | Is Seam's reference documentation incorrect when it says "The EJB container allows stateless components to be accessed concurrently, and throws an exception if multiple threads access a stateful session bean"?  It's hard for me to see how stateless session beans can be both single-threaded and able "to be accessed concurrently."
  | 

The answer is that EJB _instances_  are never accessed directly.  This holds true even if local business interfaces rather than remote interfaces are used. Even then a client never accesses an EJB _instance_ directly.  Instead, when a client references an EJB bean, it actually references a proxy object provided by the EJB container.  Thus, the EJB container can intercept calls to this proxy object and dispatch incoming calls to different bean instances as needed, in order to ensure that only a single thread operates on a bean instance.

In the case of a stateless session bean (SLSB), the bean instance does not hold any conversational state.  Therefore, the  EJB container typically maintains a pool of SLSB instances, and on receipt of an incoming call to a proxy object, it selects an instance out of this pool to which it routes the call.  When there are concurrent incoming calls to a proxy object, the container can thus dispatch these calls to different bean instances.   Each bean instance  sees only a serialized sequence of method calls.

As for stateful session beans (SFSB), they do hold conversation state, often they are referred to as an "extension of the client".   SFSBs conceptually execute on behalf of single client. They are not meant to be shared by more than one client at the same time.  This implies they cannot be called by the same client using multiple threads.  Clients are not allowed to make concurrent calls to a stateful session object. If a client-invoked business method is in progress on a bean instance when another client-invoked call, from the same or different client, arrives at the same instance of a stateful session bean class, the container may throw the java.rmi.RemoteException to the second client, if the client is a remote client, or the javax.ejb.EJBException if the client is a local client. This restriction does not apply to a stateless session bean because the container routes each request to a different instance of the session bean class.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4084390#4084390

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4084390



More information about the jboss-user mailing list