Distributed Objects   «Prev  Next»

Lesson 5Session beans
Objective Difference between stateless and stateful Session beans

Difference between stateless and stateful Session Beans

Session bean description

A Session bean, whether stateful or stateless, is best understood by looking at its characteristics.
Look at the diagram below and then examine the list of characteristics:
  1. A client can communicate to an EJBOjbect by means of 1) RMI, 2) Corba, 3) COM
  2. A session bean is created on behalf of a single client
  3. A session bean must implement the Session Bean interface
  4. The client uses a naming service to locate the session bean

1. A client can communicate to an EJBOjbect 2.A session bean is created on behalf of a single client
1. A client can communicate to an EJBOjbect 2.A session bean is created on behalf of a single client

  1. Executes on behalf of a single client. There is a one-to-one relationship between the client and the bean instance. In the diagram above, each client is associated with a single bean.
  2. Can have a transaction associated with it.
  3. May update shared data in an underlying database, but it does not directly represent the shared data.
  4. Is relatively short-lived. How long is short-lived, you may well ask? The EJB specification defines it as a fraction of a second to as much as a few months. It assumes that it does get removed (remove is equivalent to delete) at some point after its creation.
  5. Is removed when the container crashes. The state of the bean instance will be lost. The client will have to re-establish a new session bean instance to continue computation.
A typical EJB container will provide a scalable runtime environment to execute a large number of session bean instances concurrently and safely.
In the next lesson, stateful and stateless session beans will be discussed.