Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Javaee6 Types of Enterprise Beans

Related Tutorials


 
 

Share on Google+Share on Google+

Types of Enterprise Beans

Advertisement
In this section we will discuss about the types of Enterprise Beans.

Types of Enterprise Beans

In this section we will discuss about the types of Enterprise Beans.

Summarily there are two types of Enterprise Beans. These are as follows :

  1. Session Bean and
  2. Message-driven Bean

Now I am discussing these beans in detail

Session Bean

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 :

  1. Stateful session beans
  2. Stateless session beans
  3. Singleton 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.

When to use Session Beans

Stateful Session Beans should be used in the following cases :

  • When state of bean specifies the interaction of a specific client and the bean.
  • When client information is required to keep by the bean across method invocations.
  • When the bean plays a role of mediator between the client and the components of an application which provides a simplified view to the client.
  • Where the work flow of various enterprise beans are required to manage by the bean in background.
  • Stateless Session Beans should be used in the following cases :

  • When state of bean has no data for a particular client
  • When in single method invocation bean is required to do a generic work for all clients.
  • When a web service is required to implement by a bean.
  • Singleton Session Beans should be used in the following cases :

  • When a state of bean is required to share across the application.
  • When only one bean is required to use concurrently by multiple threads.
  • When the specification of an application is that a bean do tasks upon startup and shutdown of an application.
  • When a web service is implemented by a bean.
  • Message-Driven Bean

    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.

    Features of Message-Driven Bean :

    There are various features of Message-Driven bean some of the following are as :

    • Act on receiving of a single client message.
    • Invoked asynchronously.
    • Comparitively short-lived
    • In the database data are not shared directly by them even accessing and updating of this data could be done by them.
    • Stateless.
    • They can be transaction aware.
    Advertisements

    If you enjoyed this post then why not add us on Google+? Add us to your Circles



    Liked it!  Share this Tutorial


    Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

    Posted on: December 2, 2011

    Related Tutorials

    Discuss: Types of Enterprise Beans  

    Post your Comment


    Your Name (*) :
    Your Email :
    Subject (*):
    Your Comment (*):
      Reload Image
     
     
    Comments:0
    DMCA.com