I tried on my own pc, two interfaces (one local the other remote) with the same methods declared.
package calc;
import javax.ejb.Remote;
@Remote
public interface CalculatorRemote {
public int add(int a, int b);
public int sub(int a, int b);
}
In another bean I inject both interfaces and uses them:
@EJB
public CalculatorRemote myRemoteCalc;
@EJB
public CalculatorLocal myLocalCalc;
public String fastest(int iter){
myRemoteCalc.add(5,6);
myLocalCalc.add(5,6);
long inittimeLocal=System.currentTimeMillis();
for(int j = 0; j<iter; j++){
myLocalCalc.sub(28, 26);
myLocalCalc.add(134778, 1234);
}
long LocalTime=System.currentTimeMillis()-inittimeLocal;
long inittimeRemote=System.currentTimeMillis();
for(int i = 0; i<iter; i++){
myRemoteCalc.sub(28, 26);
myRemoteCalc.add(134778, 1234);
}
long RemoteTime=System.currentTimeMillis()-inittimeRemote;
if(LocalTime>RemoteTime){
return "Local slower than Remote " + (LocalTime-RemoteTime) + " ms difference with remote processing in "+ RemoteTime + "ms and local processing in"+ LocalTime + " ms. ";
}
return "Remote slower than Local " + (RemoteTime-LocalTime) + " ms difference with remote processing in "+ RemoteTime + "ms and local processing in"+ LocalTime + " ms. " ;
}
When I call the method fastest (used to determine which of the remote or local call is the fastest) the result gives at each time a time factor of 5 between the two access methods.
here are the outputs:
it gave the following output for 200000 iterations:
Remote slower than Local 46 015 ms difference with remote processing in 58 609 ms and local processing in 12 594 ms.
and the following output for 100000 iterations:
Remote slower than Local 23 406 ms difference with remote processing in 29 609ms and local processing in 6 203 ms.
and the following output for 1000
Remote slower than Local 219 ms difference with remote processing in 297ms and local processing in78 ms.
that's quite strange that SUN nearly advises us to use only one type of interface in the source of Gregory at the end of the section he refers to:
While it is possible to provide both a remote client view and a local client view for an enterprise bean, more typically only one or the other will be provided.
in this case, with only remote access, the calls will be slow and noone would get the advantages of local fast-access.
I think that any bean should have a local interface which includes the methods of the remote interface. The remote interface methods would be a subset of the local interface methods. with this we are sure that remote clients are served on a normal way while local ones are served on a fast way.
Do they tell that only to encourage us to provide different beans for internal and external stuff? or is it because in more complex methods local and remote access will differ greatly?