Concurrency with Remote References of Stateless Session Beans?


EJB design: Concurrency with Remote References of Stateless Session Beans?

  1. Can the Remote references of Stateless Session Beans (or any other Beans for that matter) be used concurrently?
  2. Yes, the remote reference of any EJB except Stateful SB may be used concurrently.

  3. What is the rationale behind the prohibition of concurrent access to a stateful bean? I have a client who spawns multiple threads and asynchronously goes out to message bus, and then would like to call the same stateful session bean with results of the bus call. Any concurrenct hits on the stateful bean should be serialized like entity beans. Seems to me this is a very arbitrary decision on Sun's part.

    By the way, what is REALLY needed is an annotated EJB spec, so the obscure reasons for some rules would be more apparent, something like the Annotated XML spec.

    -- Sam
  4. I agree with you, there are situations where it would be very useful to have concurrent access to a SSB. That is why some EJB servers allow concurrent accesses (you may specify it at deployment time) but it is not supported by the specs.

    In EJB 1.1, concurrent access to a SSB were strictly forbidden.
    In EJB 2.0, they added a few notes (e.g. see note 4 in 7.5.6) saying that instead of throwing exception, the container may serialize accesses to a SSB. But the developper still cannot rely on that behaviour.
    Wait and see the next release of the specs...

  5. The reasoning behind nonconcurrent access to sfsb is sfsb is suppose to br per client, an extension of the client, not shared state. If you allow concurrent access the container will have a hard time determining if it's the threads of the original client (your situation) or some other client (violation).