Stateful session bean multi-threaded access

痴心易碎 提交于 2019-12-10 10:04:15

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/23287054/stateful-session-bean-multi-threaded-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!