Dears .. I have a question about session beans(stateless/statefull): if tow clients want access the same session beans,does the session beans service just one client , and when finish him, he will go to service the second one??. rehards
In the case of stateless beans an instance serves each client call, it may or may not be the same instance, depending entirely on how the container responds. In the case of stateful beans, each client has its own instance, since the instance is tied to the session.
The container will serialize calls to each call to a session bean instance. Each session bean instance will see a serialized sequence of method calls; so yes if two clients call the same method on a stateless session bean and are directed to the same instance of that bean by the container then the second call will have to wait until the first call has completed.
It is common to create and maintain a pool of stateless session bean instances. Each client call will be serviced by an available instance (usually in a separate thread). The instance will remain active until the end of the method call, after which the EJB container will unbind the session bean from the client and return the instance to the pool for reuse.
If the container has no available instances and is prevented from creating new ones, then all client calls for the EJB class will be blocked until an instance becomes available. However, should the block eventually cause a timeout, the container will throw RemoteException for a remote client or an EJBException for a local client.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
subject: how session beans service simultaneous client calls