| A common application
of session beans is to manage database transactions. A session
bean can execute database reads and writes for the client. A
session bean's fields contain the state of the conversation
and are transient. This fits transactions well since transactions
either must be committed or rolled back. If either the server
or the client becomes unavailable, the session bean is terminated.
Session beans can be used to update shared data at a potential
cost to scalability and performance. Session bean are optimally
used to access its own clients session information.
An entity bean, represented by an entity in a database, provides
access to methods needed utilize that data. As long as the data
remains in the database, the entity bean persists. Persistence
can be bean managed (BMP) or container managed (CMP). Using
entity beans, developers can make the data available to multiple
clients simultaneously while minimizing callbacks. Applications
can manipulate entity beans as Java object references since
entity beans persist and abstract the bean and container services.
The use of entity beans can represent a big improvement over
the use of stateful session beans. Entity beans manage state
better than session beans by way of special callbacks which
reduce the number of method calls needed. However, many similar
callbacks are available to session beans using the javax.ejb.SessionSynchronization
to access transaction status data.
Message-driven beans are used in situations when communication
takes place asynchronously. Message beans have no client interfaces.
They are message listeners, accessing messages from queues or
container subscriptions. When the container receives a message
it invokes an iteration of the appropriate message bean. Clients
can only access the bean by way of messages sent through Java
Message Service and directly. The stateless nature of this communication
means that message beans can be pooled in a way that is similar
to pooling stateless session beans. As the inbound and outbound
messages are Java Message Service messages via JMS Queue.
|