Prepare Interview

Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

EJB Interview Questions and Answers

Ques. Explain the life cycle method of EJB?

Life Cycle of Entity Bean:

  • First stage is Does Not Exist Stage then Container creates the instance of EJB and call SetEntityContext() method which will set all entity context to bean and now it will become available on pool, to get a particular identity of an EJB object it has to move from Pooled stage to ready stage which is done by calling the create() method which in turns call ejbCreate() and ejbPostCreate() method.
  • There is another way by which directly entity bean can move to pooled stage to ready stage that's is call ejbActivate() method. Now we are ready to invoke the business method of entity bean .After completion of business method if we want to move again in pooled stage from ready stage we can call remove() method which in turns call ejbRemove() or directly call ejbPassivate() method.
  • At the end container remove the instance of EJBfrom pool and call unSetEntityContext().
Life Cycle of Stateful Session Bean:
  • Stateful session beans life cycle starts when client call create() method.The container create the instance of session bean and call setSessionContext() and ejbCreate() method.
  • Now the stateful session bean is ready to serve the client request after serving the request if it is not used after a long time container can move this bean to passive stage by calling the ejbPassivate() method.similarly when bean is in passive stage and client invoke the business method the container call ejbActivate() method to move bean from passive stage to active or ready stage.
  • At the end of life cycle client call remove() method and container will call ejbRemove() method and bean is ready for garbage collection.
Life Cycle of Stateless session bean:
  • Stateless session bean has short life cycle it can have two stage does not exist and ready stage. ejb container create the instance of stateless session bean and call setSessionContext() and ejbCreate() method.Now the bean is ready to invoke business method on will not maintain the state so remove () method is been called after completion of business method which in turns call ejbRemove() and now its ready for garbage collection.
Life cycle of Message Driven bean:
  • MDBs have same life cycle like stateless session bean. setMessageDrivenContext() method and ejbCreate() method is called by container to create the instance of its ready to receive message and at the end of lifecycle client will call remove() method which in turns call ejbRemove() and now its ready for garbage collection.
Is it helpful? Yes No

Most helpful rated by users:

©2021 WithoutBook