Remote EJB3 invocation
Are remote EJB calls, made from the same application server, alwa开发者_JAVA技巧ys 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).
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.
精彩评论