2.2.3 Enterprise Beanのライフサイクル

Enterprise Beanのライフサイクルについて,Enterprise Beanの種類ごとに説明します。

<この項の構成>
(1) Session Beanのライフサイクル
(2) Entity Beanのライフサイクル
(3) Message-driven Beanのライフサイクル

(1) Session Beanのライフサイクル

Session Beanのライフサイクルは,次に示す場合によって異なります。

(a) Stateless Session Beanの場合

Stateless Session Beanのライフサイクルを次の図に示します。

図2-1 Stateless Session Beanのライフサイクル

[図データ]

does not exist:
Stateless Session Beanが存在しない状態
method-ready pool:
Stateless Session Beanが実行可能状態としてmethod-readyプール内に存在する状態
(b) Stateful Session Beanの場合

Stateful Session Beanのライフサイクルを次の図に示します。

図2-2 Stateful Session Beanのライフサイクル

[図データ]

does not exist:
Stateful Session Beanが存在しない状態
method-ready:
Stateful Session Beanがアクティベイトされ,実行可能状態としてmethod-readyプール内に存在する状態(トランザクションなし)
method-ready in TX:
Stateful Session Beanがアクティベイトされ,実行可能状態としてmethod-readyプール内に存在する状態(トランザクションあり)
(c) Singleton Session Beanの場合

Singleton Session Beanのライフサイクルを次の図に示します。

図2-3 Singleton Session Beanのライフサイクル

[図データ]

does not exist:
Singleton Session Beanが存在しない状態
method-ready
Singleton Session Beanが実行可能な状態

Singleton Session Beanの初期化は,EJBコンテナによって実行されます。なお,初期化のタイミングは,アノテーションの指定によって,アプリケーション開発時に明示的に定義できます。

Singleton Session Beanのインスタンスは,初期化されると,アプリケーションが停止するまで存在します。Singleton Session Beanが破棄されるタイミングでのEJBコンテナの動作は次のとおりです。

(2) Entity Beanのライフサイクル

Entity Beanのライフサイクルを次の図に示します。

図2-4 Entity Beanのライフサイクル

[図データ]

does not exist:
Entity Beanが存在しない状態
pool:
Entity Beanがパッシベイトされ,passiveプール内に存在する状態
ready:
Entity Beanがアクティベイトされ,readyプール内に存在する状態

(3) Message-driven Beanのライフサイクル

Message-driven Beanのライフサイクルを次の図に示します。

図2-5 Message-driven Beanのライフサイクル

[図データ]

does not exist:
Message-driven Beanが存在しない状態
method-ready pool:
Message-driven Beanがmethod-ready状態で,ServerSessionプール内に存在する状態