I am reading book on EJB but I am not getting the difference between Remote Interface & Local Interface. Both Interfaces are used for Stateless & Statefull Session Beans. so on which condition it is determined which one to use.
suppose there is Server S on which EJB Container & my project resides. client A , B & C access S . so in my application which interface would be use local or Remote ?
Stateful - is used if you want to have multiple operations & specific to single client
(One stateful instance for a client)
Stateless - container create a pool of instances & forward it when a client request comes, does not matter who is the client
(One instance can serve multiple clients)
Local interface - used if EJB will be accessed locally (same env)
(so you can have local interface for stateful as well as for stateless)
Remote interface - if your ejb will be used remotely (in different env)
(& you can have remote interface for stateful as well as for stateless)
if your SessionBeans (SB) are accessed remotely by another SB, servlet or any other component then use Remote interface.
But if for example client is accessing servlet at remote address and that servlet is using SB (in servlet's env) then you can use Local interface for SB.
If clients and EJB reside in the same JVM, use local interface. eg. clients from servlet, jsp, jsf, ejb components in the same Java EE 5 container.
If clients and EJB does not reside in the same JVM, use remote interface. eg. clients from Application Client Container.
Joined: Apr 24, 2008
Thank you Sugon & Deepika ..
yes its a beginning .
Still in little confusion . if client access some session bean on web application server then we use Local Interface and that session bean access some other session bean on different physical server then we should use Remote Interface .
am I correct ?
In one physical machine can we have 2 different JVM's ?
" clients and EJB resides in same JVM " please clarify the statement.
Joined: Feb 24, 2009
if client access some session bean on web application server
- web server is used to deploy web component (e.g. servlet, jsp,...)
- application server is used for enterprise application components & design to have EJB Container/server, web server, messaging,....
web application server can not deploy EJB. But an application server can deploy web application & EJB.
I hope you meant application server and not web application server.
that session bean access some other session bean on different physical server then we should use Remote Interface .
that other session bean should use (implement) remote interface, you are correct.
In one physical machine can we have 2 different JVM's
Open 3 command prompt & run same or three different Java programme at same time, you are already using 3 JVM on same machine.
" clients and EJB resides in same JVM " please clarify the statement
A client is who is asking for a service and a server (here server is server object and not application or web server) is who is asked for the service.
A client could be an application or object (a reference) who is requesting a service (called operation or method call) to a server object (EJB, other java object)
a client is an object which invoke / call the method and server (object) is whose method is called. Server object could be any Java object (an EJB is also a Java Object)
clients(servlet, another EJB, .....) and EJB (you want to call method of this EJB) resides in same JVM