Can you explain in brief life cycle for stateless and stateful beans?Stateless Session Bean Lifecycle
The stateless session bean does not become passive, so its life cycle has two stages:
1. Does Not Exist: In this stage bean has not been instantiated.
2. Method Ready pool: In the Method Ready Pool stage bean has instances 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.
Stateful Session Bean Lifecycle
There are three stages in the lifecycle of Stateful Session Bean. These are:
1. Does Not Exist: In this the bean does not have any instance.
2. 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 serves only one client.
3. Passive: 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.
|