This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling a EJB from another EJB

 
Nikhil Jain
Ranch Hand
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to call a EJB from another EJB. I did this by JNDI lookup & then doing the usual stuff for calling the EJB. So Is there any better way of doing this. Because, wound'nt this be a overhead.. i mean maknig a lookup.
 
Mansur Khan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If both your EJB's are on the same application server, they can use EJBLocalObject and EJBLocalHome Interfaces to better the perfomance during look. Or may be a cached service locator can help. An approach like Spring can help better through DI (IOC). I will not want to talk on the Spring Approach as it would be out-of-scope.
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shashank,

You could implement two J2EE design patterns in this case. [1] Session Facade & [2] Service Locator. You can maintain a Session Bean as Session Fa�ade on the EJB container. So the client side business delegator would always interact with this Session Facade by looking up for the Session Bean (Session Fa�ade) by using Service Locator. In this case, this call would be the remote call and for that you would be using EJBObject and EJBHome. This session facade would be the entry point to access other EJB's. Other EJB calls would be local calls for the session fa�ade and for that you would be using EJBLocalObject and EJBLocalHome and this practice would increase the performance of your app. This is applicable if all the EJB�s are deployed on same application server.

Thanks,
Mahesh

-------
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic