In this section we will discuss about the types of Enterprise Beans.
Summarily there are two types of Enterprise Beans. These are as follows :
Now I am discussing these beans in detail
A Session bean is a non persistent object that encapsulates business logic onto which a client can take action programmatically across the local, remote or web service client views. When an application is being accessed which are deployed on the server, client invokes the methods these methods are the session bean's methods. The session bean is operated for their clients, and protects it from the complexity when the business task is run within the server. Mapping of client and session is one-to-one i.e. each client is provided to its own session object. Session bean's class instance (session object) can't be used by the client without intervening the session bean's home and component interfaces i.e to use the session object, client will have to go through the session bean's home and component interfaces.
There are three types of Session Beans :
Stateful Session Beans
Object's state contains the instance variable values. An unique client/bean session instance variables values denotes stateful session bean. In a stateful session client communicates with its bean continuously so it is very useful for conversational session where the state between instance variable values and method invocation need to be maintained. State of stateful session bean is preserved between the method calls. So, a stateful session bean is mapped client and session bean into one-to-one i.e created an only one instance of a stateful session bean for each client. A stateful session bean can not implement a web service.
Stateless Session Beans
A Stateless session bean is a bean where the communication between client and its bean is not required continuously i.e. it does not preserved the conversational session with the client. When in such type of beans method's are invoked by the client a client specific state may contained the bean's instance variable values within the method invocation period. Stateless session beans can provide a better scalability for application where numerous clients are required. Web service can be implemented by the stateless session bean.
Singleton Session Beans
Singleton session bean represents once instantiation for each application and used for sharing across the application and concurrently accessed by clients. Using singleton session bean similar operations of stateless session beans can be performed but it is quite different from stateless is that the singleton session bean is instantiated only once. State of singleton session bean is preserved when the invocations between client but need not to preserve their state over server crashes or shutdowns. Web service endpoints can be implemented by the session bean.
Stateful Session Beans should be used in the following cases :
Stateless Session Beans should be used in the following cases :
Singleton Session Beans should be used in the following cases :
An Enterprise bean which is used in Java EE applications to provide the process of messages asynchronously. JMS messages or any messaging types can be processed by the Message-Driven Beans.
Where to use Message-driven beans :
Because of the session bean provides the facility of sending and receiving messages synchronously so, when you are required to send and receives messages asynchronously you should use the Message-driven beans.
There are various features of Message-Driven bean some of the following are as :
Liked it! Share this Tutorial