Types of EJB


             Basically Ejb is divided into two types.One is Session Beans and another is Message Driven Beans(MDB), In this article We are going to see only about Session Beans.We will have a separate article on MDB.


Session Bean:

                   In the 3-tier Architecture design ,Business Layers usually contains Session Beans classes. This Session Beans class is nothing but the normal class annotated with three EJB session bean Components(Stateless,Stateful,Singleton).

Why we need to declare normal class into the Session Bean class?

 Once we declared our class as Session Bean class then it can avail all the features provided by the Ejb container.

Who are all the Clients for Session Bean?

  1. Clients who call session Bean from the Presentation Layer( html or jsp ) within the Application server. 
  2. Clients can be a  session bean who call another session bean with the Application server (i.e Same JVM) usually called as Local Client.
  3. Clients can be a session bean who call another session bean from the another Application server(i.e Different JVM) usually called as Remote Client.
Note: Each session bean must contain interfaces for their class.At the Run time EJB provides runtime implementation for all the session bean interfaces,When clients calling the session beans Ejb won't allow clients to call  Session beans classess directly instead all calls goes to the proxy classess.

What is this Proxy Classess?

                   This proxy classes maintly used to do container managed things like transaction management,security,asynchornous thread management etc...

 Session Beans are sub-divided into 3 types,


  1. Stateless
  2. Stateful
  3. Singleton

Stateless Session Beans: (Does not maintain state of a client)

                           For stateless session beans EJB container create a pool of instances for a each stateless beans.And also it does not maintain client state, what it means? lets see the diagram.

Stateless Session Bean



                                  
                                  Consider that our application contain single session bean class which deployed in the application server.

                                  At the run-time ejb container container created pool of instance for a our stateless session bean class.

Why EJB container creates pool of instances for a Stateless Session Bean? 


                  In the Enterprise application several client will call the session bean at a time.To serve fast services to the clients EJB container creates this pool of instances when application started. 

Before I told that it does not maintain the state.

            Consider that client contain the set of methods,first method make a call to the session bean in that time container randomly pick the instance and returns to the client.In the next method call client makes a call to the same session bean.In this time client wont get the instance object which returns previously Ejb container randomly pick any instance from the pool of the instance and return it back to the client.It clears that its not maintaining the client state.


Stateful Session Beans: ( Maintains client state across each request, one bean instance per client)


                                   In Stateful session bean EJB container creates single session bean instance for each client.And also note that it won't create pool of instance like stateless  at the application startup.It creates instance when the client makes request to the bean.And also it provides same bean instance for each subsequent request call from the client.


Stateful Session Bean




Singleton Session Beans: ( One bean instance per application server)

                                     Same as like in design patterns , In singleton session Bean EJB Container creates one instance for whole application.so any number of client will request for the session bean only one instance is shared accross the clients.




Singleton Session Bean



Hope It is Informative.If you are not understood fully don't worry We will have nice programmatic example for each Session Beans in upcoming Articles.


Thanks Have a Happy Learning...



































Share this

Related Posts

Previous
Next Post »