Stateful Session Bean

SA stateful session bean is an extension of the client application. It performs tasks on behalf of the client and maintains state related to that client. This state is called conversational state because it represents a continuing conversation between the stateful session bean and the client. Methods invoked on a stateful session bean can write and read data to and from this conversational state, which is shared among all methods in the bean. Stateful session beans tend to be specific to one scenario. They represent logic that might have been captured in the client application of a two-tier system. Session beans, whether they are stateful or stateless, are not persistent like entity beans. In other words, session
beans are not saved to the database.

Stateful session beans offer an alternative that lies between entity beans and stateless ses sion beans. Stateful session beans are dedicated to one client for the life of the bean instance; a stateful session bean acts on behalf of a client as its agent. They are not swapped among EJB objects or kept in an instance pool like entity and stateless bean instances. Once a stateful session bean is instantiated and assigned to an EJB object, it is dedicated to that EJB object for its entire life cycle.

Stateful session beans maintain conversational state, which means that the instance variables of the bean class can cache data relative to the client between method invocations. This makes it possible for methods to be interdependent, so that changes made by methods to the beanís state can affect the result of subsequent method invocations. In contrast, the stateless session beans we have been talking about do not maintain conversational state. Although stateless beans may have instance variables, these fields are not specific to one client. A stateless instance is swapped among many EJB objects, so you canít predict which instance will service a method call. With stateful session beans, every method call from a client is serviced by the same instance (at least conceptually), so the bean instanceís state can be predicted from one method invocation to the next.

Some important points

1) Conversational State? A stateful session bean performs tasks on behalf of the client and maintians state related to that client. This state is called conversional state. Because it represents a continuing conversation between the stateful session bean and the client.

2) Stateful Session beans are available only through handle object as for as the specific bean instance is kept alive in the EJB server.

3) The bean instance not swapped among EJB object.

4) Stateful session beans doesn't use instance pooling.

5) The EJB object reamins connected to the client, but the bean instance is dereferenced and garbage collected during inactive periods.

6) If ejbRemove(), Attributes of instance are wiped clean and client still has reference to instance.


Servlet Container
Servlet Context
Servlet Mapping
Session Bean
Stateful Session Bean
Stateless Session Bean
Static Field
Static Method
Use of this website constitutes acceptance of the AllAppLabs.com Terms and Conditions