Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Javabeans Stateful and Stateless Session Bean Life Cycle

 
 

Share on Google+Share on Google+

Stateful and Stateless Session Bean Life Cycle

Advertisement
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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Discuss: Stateful and Stateless Session Bean Life Cycle  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
swati prasad
June 6, 2011
EJB

I want the answers of few questions
Vijay
June 12, 2012
Life cycle of EJBs

The illustation with diagram is Easy to understand and grasp.
DMCA.com