Local vs. Remote Interfaces in EJB (EJB3)

There are two different interfaces available when you are writing an EJB. One is remote and one is Local. Remote, as it name suggests is for remote client that want to remotely call (or fire) functions and get some results. On the other hand Local is designed to be used in a local environment, for example in a case if another EJB or even a POJO in your system is using that. The usage would be the same as when you want to use an EJB using its Remote interface. However, it has less headache for the server to handle that. That’s the only reason you might want to use a Local interface instead of Remote interface. Local interface is not local to JVM but local like an other POJO class.

Local client view cannot be accessed:

  • When an EJB or web component is packaged in a different application’s EAR packages. 
  • When a web component is deployed in a web container, and EJBs are deployed in an EJB container, and these containers are separated (even if they are running on the same machine)

These are main factors in considering a Local or Remote interface:

  • Client: if your client is not a web component or another bean do not use Local 
  • Beans & Beans: Are the beans loosely coupled? then it is a good idea to use Local 
  • Scalability: Remote is always better for scalability 
  • Local interfaces are recommended for entity beans, which helps with performance issue.

More to read:

Leave a Reply

Your email address will not be published. Required fields are marked *