Java Tutorial - Java Scipt : Stateful Session Beans

Java Tutorial - Java Scipt :

Stateful Session Beans


Stateful session beans are like their stateless counterparts, except that their state is maintained over a client session. This makes stateful session beans a logical way to hold client information on the server side. In this regard, a stateful session bean can be thought of as an extension of the client’s session storage. Items in a shopping cart, for example, can be stored within a stateful session bean that maps to a single client. This is the theory behind stateful session
beans. Note that a client session has a relatively short lifespan, as opposed to persistent EJBs that keep their state indefinitely. Nevertheless, the addition of state makes stateful session beans much more expensive for an EJB container to maintain. This becomes more of an issue in the case of clustered deployments. Although this is technically transparent to the developer, in real-world usage you have to pay careful attention to the use of stateful session beans and their impact on the scalability of your application. Note also that, unlike stateless session beans, stateful session beans do not support concurrent calls, which further erodes their performance. Developers often opt for lighter-weight mechanisms that store the state closer to the client. For a Web-based interface, one might choose to store the session state in an HttpSession instead. The advantage with this approach is that you can save the extra expense of EJB hoop jumping, such as having to perform an EJB lookup to find the stateful session bean. However, the solution then becomes tied to that type of client. For each additional client type, say a WAP (Wireless Application Protocol) client or a thick Java GUI client, new state-handling mechanisms must be added.