javamultithreadingconcurrencyejbstateful-session-bean

Stateful session bean multi-threaded access


The EJB 3.2 spec says the following:

By default, clients are allowed to make concurrent calls to a stateful session object and the container is required to serialize such concurrent requests. Note that the container never permits multi-threaded access to the actual stateful session bean instance.

To me concurrent access and multi-threaded access seem equivalent. So how is it possible to make concurrent calls to a stateful EJB while multiple threads are prohibited?


Solution

  • You are right: Concurrent calls can only be made with multiple threads. So, when speaking about concurrency, there are multiple threads involved.

    The spec clearly says that the container is not allowed to concurrently access one stateful session bean instance. If there are concurrent calls (from multiple threads), the container must serialize them.

    Note, that there could of course be several instances of that stateful session bean, which of course can be accessed by several clients.

    Additionally - and that seems to confuse you - the spec say that a client (not the container) is allowed to make concurrent calls, but the container then must serialize them.