2

我再次浏览 Javaee7 oracle 文档,这就是所说的。

“一个单例会话 bean 为每个应用程序实例化一次,并且在应用程序的生命周期中存在。单例会话 bean 设计用于单个企业 bean 实例在客户端之间共享和并发访问的情况。”

我完全理解它在说什么。但是仔细想想,会话这个词在这里非常具有误导性。由于它存在于应用程序级别,因此术语“会话”似乎不适用于此处。

当我想到“会话”这个词时,我认为每个单独的用户都是一个会话。如果该单例会话 bean 用于跨应用程序,那么它不应该被称为会话 bean(相反,可能会更好地理解应用程序 bean)。

有什么意见吗?

4

2 回答 2

0

When i think of the word 'session', i think in terms of each individual user as a session

The term "session" in this context means unit of work or business transaction.

In Stateless and Singleton beans, a new session/business transaction is opens when a new request arrives, and it lives until the response it sent back to the client. (session-per-request pattern)

For Stateful Session bean the business transaction could implies several client requests. From the Stateful bean's perspective, a client is a proxy that sends the requests to the same stateful instance.

Edit (too long for comment)

I think Application Bean could probably be a good name, in fact they are good for storing application settings, but the key point is why they are called Session Bean.

In this context "session" is the period of time the business transaction executes. For Stateless and Singleton this period matches with the request/response cycle.

...If that singleton session bean is for across application, shouldn't it not be called a session bean

The fact that a Singleton maintains its state between client invocations doesn't means that the session-per-request model doesn't applies. Every Singleton reference used in your application is a client, when a client makes a request a new session is created.

于 2013-12-06T02:56:06.647 回答
0
  • 无状态 - 会话持续单个客户端操作
  • 有状态的 - 会话在客户端的操作中持续存在
  • 单例 - 会话持续跨客户端应用程序
于 2013-12-07T17:23:15.110 回答