Stateful and Stateless Session Bean Life Cycle

Ads
 

Stateful and Stateless Session Bean Life Cycle

Stateful and Stateless Session Bean Life Cycle

Stateful and Stateless Session Bean Life Cycle

Understanding Stateful and Stateless Session Bean Life Cycle

      

In this section of EJB tutorial, we will learn about the lifecycle of Stateful and Stateless Session Beans.

Stateless Session Bean Life cycle

There are two stages in the Lifecycle of Stateless Session Bean. These are:

a) Does Not Exist
In the Does Not Exist stage, bean does not have instance in the memory. In this stage bean has not been instantiated.

b) Method Ready Pool
In the Method Ready Pool stage bean has instance(s) in the memory of the EJB container and it is ready to serve clients. On the startup of the EJB container some instances of the bean are created and placed in the pool. EJB container creates the new instance of the Bean and then sets the session context (setSessioncontext()) and it calls the ejbCreate() method to place the bean in the Method Ready Pool stage. Container calls the ejbRemove() method to move the bean into Does Not Exist state.

Following Diagram shows the Life cycle of Stateless Session Bean

Stateful Session Bean Life cycle

There are there stages in the life cycle of Stateful Session bean Life cycle. These are:

a) Does Not Exist
This is the Does Not Exist stage, bean does not have instance in the memory. In this stage bean has not been instantiated.

b) Method Ready Pool
In the Method Ready Pool stage bean has instance in the memory of the EJB container and it is ready to serve client. One instance of the Stateful Session Bean servers only one client. When Client Calls create(args) method on the Home Interface, server creates new instance of the bean and sets the Session Context and then container calls the ejbCreate(args) method on the bean and places the bean into Method Ready Pool stage. ejbRemove or Timeout moves the bean into Does Not Exist stage.

c) Passive state
In the Passive state the bean is passivated to conserve the resource. The passivate method is called before the instance enters the "passive" state. The instance should release any resources that it can re-acquire later in the ejbActivate() method. After the passivate method completes, the instance must be in a state that allows the container to use the Java Serialization protocol to externalize and store away the instance's state. ejbRemove or Timeout moves the bean into Does Not Exist stage.

Following Diagram shows the Life cycle of Statelful Session Bean

Stateful Session Bean Life cycle

Ads

Ads