6

私の理解によると、ステートレス セッション Bean はビジネス ロジックのコーディングに使用されます。インスタンスが複数のリクエストで共有されているため、インスタンス変数にデータを格納できません。そのため、Singleton クラスに似ているようです。ただし、違いは、要求ごとにステートレス セッション Bean の個別のインスタンスを作成 (またはプールから再利用) することです。

グーグルで調べたところ、Java EE 仕様ではシングルスレッドであると想定されているという理由が見つかりました。しかし、 SINGLE THREADEDと指定されている理由がわかりません。

4

2 に答える 2

5

TX コンテキストのため、SLSB はシングル スレッドです。プリンシパルは、呼び出されたときに Bean インスタンスに関連付けられます。これらの Bean はプールされ、最大プール サイズに達しない限り、別のスレッドで処理されます (ベンダーによって異なります)。

SLSB がスレッド セーフに設計されている場合、すべての呼び出しは、 Tx Context 、 Security Context info などを含むリクエスト情報を含むサーブレット doGet/Post のように見えます。そのため、少なくともコードはきれいに見えます (開発者によって異なります)。

于 2008-08-27T08:29:56.780 に答える
4

The primary reason stateless session beans are single threaded is to make them highly scalable for the container. The container can make a lot of simplifying assumptions about the runtime environment. A second reason is to make life easier for the developer because the developer doesn't have to worry about any synchronization or re-entrancy in his business logic because the bean will never be called in another thread context.

I remember the reasoning being discussed in the reviews of the original EJB 1.0 specification. I would look at the goals section of the specification. See http://java.sun.com/products/ejb/docs.html for the list of specifications.

于 2008-08-27T14:47:40.787 に答える