Objective 4.2: Distinguish stateful and stateless Session beans

Session Beans

Session Beans represent the business logic or workflow carried out on request of a client.
There are two versions of Session Beans: stateful and stateless

Stateful Session Bean

Stateful Session Beans have the ability to maintain the state of the "conversation" (method calls) between the client and the bean. That is, a Stateful Session Bean serves one client as long as this client communicates with the bean in a single conversation (session).

When needed, the container may decide to "passivate" the bean. This has performance impact.

Stateful session bean lifecycle:

Stateless Session Bean

Stateless session beans serve one method call and then forget about the client. That is, they do not have the ability to remember the client state across multiple method calls. After servicing the method, the bean is returned to the pool. This is actually an application of the FlyWeight pattern, improving performance and scalability by sharing resources.

Stateless session bean lifecycle:

Hall of fame

  • Me: Part I 81%
  • Heros