Wednesday 7 May 2014

01_EJB_Introduction_TO_EJB

EJB

  • EJB stands for Enterprise Java beans.
  • This will come into service layer in the J2EE architecture where all of our business logic reside.
  • For example business operations like manupulating database,sending mails,sending messages to message queues.
  •  J2EE container Provides some facilities to EJB like Transaction,security,pooling,concurrency,Timers,Intersepters..

Types of EJBS


1.Stateless Session Bean
  • The container usually maintains a pool of instances of beans.
  • When a client invoke the method of bean  first one instance may picked up by the container and one more time the client trying to access the other method  in the bean may be some other instance invoked by the container.So first instance may not aware of the values of other instance of the same bean.So we cant store state info in this case.

  • We should not save the State in this bean.Means we cant store any values for the variables and state information  like 
                               @stateless
                               Public String getHello( String Name){
                               String EmpName=Name; //We cant store like values
                               }

  • Most of the business operations are singular.Like sending Mails and logging in user..They dont want to store the state of information.In such cases we may use Stateless session bean.
 In this type of beans the container managed the pool of instances.
.
2.Stateful Session Bean


  • This beans are Client oriented.There is one instance of bean for each client.
  • If a client invoke a method of bean one instance get created and the client will invoke another method of the bean  and save some state and second time the perticular instance only get picked up for the specific client.So it will maintain the state information.
  • There is no pool of instances of the bean in the container,the instance is created just before the client get serviced.
 




  • The client is supposed to issue the command in this type of bean.But in stateless session bean container will maintain the instances.



3.singleton Session Bean
  • Only one instance this bean per application server.Every client will invoke the same instace anyway some concurrency mechanisms are there to avoid conflicts.
  • If we have 2 JVMs in our server it will create two singleton instances per each JVM.Also in distributed systems environment we have different JVMs and this sigleton bean will create each instance per each JVM:)



Note:

Clients:


Lets  assume one bean in service layer(EJB).This bean may be accessed  by  another bean(another EJB) in the same layer or  in web layer(using JSP or JSF) or some other layer with the same container or from  outside..

Local:Beans reside within application server.
Remote:When beans reside outside the Application server known as Remote clients.

No comments:

Post a Comment

test