简体   繁体   English

有状态会话bean多线程访问

[英]Stateful session bean multi-threaded access

The EJB 3.2 spec says the following: EJB 3.2规范说明如下:

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. 请注意,容器从不允许多线程访问实际的有状态会话Bean实例。

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? 那么如何在禁止多个线程的情况下对有状态EJB进行并发调用呢?

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. 规范明确指出不允许容器同时访问一个有状态会话bean实例。 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. 注意,当然可以有几个有状态会话bean的实例,当然可以由多个客户端访问。

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. 另外 - 这似乎让你感到困惑 - 规范说允许客户端 (不是容器)进行并发调用,但容器必须序列化它们。

A stateful session bean can process concurrent requests. 有状态会话bean可以处理并发请求。 However these calls do not actually access the bean class you've coded concurrently. 但是,这些调用实际上并不访问您同时编码的bean类。 Application server serializes these requests. 应用服务器序列化这些请求。 So at a given time only a single thread executes the bean class methods. 因此,在给定时间,只有一个线程执行bean类方法。

So the thing is, concurrent call is not equal to concurrent access for stateful session beans. 所以问题是, 并发调用不等于有状态会话bean的并发访问

This level of concurrency only handles requests of same session. 此并发级别仅处理同一会话的请求。 Requests from different sessions are handled with different objects. 来自不同会话的请求由不同对象处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM