tags:

views:

283

answers:

1

Are remote EJB calls, made from the same application server, always optimized as local, in-memory calls, and is serialization of data skipped in this scenario?

In other words, is it valid to work with remote EJBs all the time, thus achieving decoupling between application components, even if two+ EJB modules are deployed in the same container? I'm using Glassfish.

Also, if I have to do runtime lookup of the remote EJBs (I don't know the JNDI name of EJB until runtime), what is the best way to cache the calls, using as little as possible overhead on the existing EJB infrastructure provided by the app server (so, no additional libraries like Guice, just what Glassfish already offers).

+2  A: 

The argument semantics of remote services are different to that for local services. Remote services, because of their serialization behaviour, effectively have pass-by-value semantics (i.e. the arguments are copied), whereas local services are standard java pass-by-reference. This is more than just a performance consideration, it changes the meaning of what a parameter is.

Because of this, I don't think a container can optimize a call to a remote EJB interface as though it were a local one, due to this semantic difference.

skaffman
Well, I don't see why container could NOT optimize the "local" call to remote EJB interface, in fact I think I read it in Glassfish documentation somewhere. It doesn't take a lot of brains in the container to figure it out, skip the serialization part and go with pass-by-ref instead. It seems very natural.Problem background: I have an extremely uncoupled JEE system, which instantiates EJBs as they are needed in runtime (by reading their description from database), and it still needs to be very fast. So you can add EJB in runtime and the runtime "engine" of app will run it when needed.
bozo
Because when you write a remote interface, you write it expecting pass-by-value semantics. The container can't go around changing those semantics in the interests of performance, it would be changing the *meaning* of it.
skaffman
Actually, it seems you can tell container to pass-by-ref even if you're using remote interfaces in co-located EJB modules.
bozo