Stateful session bean multi-threaded access

2019-05-10 20:11发布

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?

2条回答
祖国的老花朵
2楼-- · 2019-05-10 20:52

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.

查看更多
欢心
3楼-- · 2019-05-10 20:54

A stateful session bean can process concurrent requests. However these calls do not actually access the bean class you've coded concurrently. Application server serializes these requests. So at a given time only a single thread executes the bean class methods.

So the thing is, concurrent call is not equal to concurrent access for stateful session beans.

This level of concurrency only handles requests of same session. Requests from different sessions are handled with different objects.

查看更多
登录 后发表回答