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:
- 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.
- Can have a transaction associated with it.
- May update shared data in an underlying database, but it does not directly represent the shared data.
- 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.
- 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.