Stateful Session Bean Introduction

  • Stateful Session Beans are business objects having state (values of its instance variables)
  • Because the client interacts (“talks”) with its bean, this state is often called the conversational state and represents a unique client/bean session.
  • The @Stateful annotation is used to mark the class as Stateful Session Bean.
  • Stateful Session Beans keep track of which calling client they are dealing with throughout a session.
  • A session bean is not shared and access to the bean instance is strictly limited to only one client at a time.
  • When the client terminates, its session bean appears to terminate and is no longer associated with the client.
  • When the client invokes a method on the bean marked with @Remove, it signals the end of the session with the bean.
  • The state is retained for the duration of the client/bean session. If the client removes the bean, the session ends and the state disappears.

Stateful Session Bean Examples

  • Shopping cart can be implemented by Stateful session bean where the list of items added to the cart by a user is stored in an instance variable of session bean. When a new item is added to the cart all the previous items will still be maintained by the bean until the session ends.
  • Checking out in a web store might be handled by a stateful session bean that would use its state to keep track of where the customer is in the checkout process, possibly holding locks on the items the customer is purchasing (from a system architecture’s point of view, it would be less ideal to have the client manage those locks)

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.