First page Back Continue Last page Graphics
Stateful Session Beans
Each client gets its own dedicated instance
"Creating" creates an instance
"Removing" destroys it, losing state
State diagram for a stateful session bean
Notes:
In the case of stateful beans, "creating" a session causes the server to allocate a new instance and connect the client to it. A stateful bean belongs to a single client and therefore, when removed, is destroyed, its state lost.
This diagram, from the EJB 2.0 specification, shows the life cycle of a stateful session bean. Key features of the diagram:
Bean class instances can be in one of three states: does not exist, method ready, or passive. Every type of session bean has its own pool.
A bean moves from does not exist to method ready when the client creates a new session by calling a create( ) method of the home interface.
In the method ready state a bean instance will hold data for a particular client session. Its various business methods will be called often.
A bean moves from method ready to passive when it is passivated by the container. This occurs if the session is idle for some period of time. The bean returns to the method ready state as soon as the client calls a method against it.
A bean moves from method ready to does not exist when the client removes the session, when the session times out or when any RuntimeException is thrown by a bean method. The bean instance is destroyed.