users@glassfish.java.net

Re: GF v3: Singleton pass by reference problem

From: <glassfish_at_javadesktop.org>
Date: Tue, 13 Apr 2010 07:42:24 PDT

Thanks for the detailed info. I can see two potential issues.

The first is the way the reference is registered :

public void init() {
manager.register("EJB01", this);
}

The "this" pointer should never be passed outside of a bean. Only the container should have access to the actual bean instance. If you need to pass a reference to a bean you need to pass an actual ejb reference object instead. In the case of a client, that's the object returned from a lookup. If a bean itself wants to pass its own ejb reference, it can acquire it via the SessionContext.getBusinessObject method. This should also allow you to remove the Registerable interface. It's not necessary since Remote ejb references can automatically be passed as parameters and return values.

Secondly, we don't recommend packaging application code and putting it in the server's lib directory. If more than one application shares the same interfaces they should be replicated in each application. Putting the code in the lib directory means there is no way to update it once it is loaded in the JVM. Replicating the classes is not ideal either but once we have well-defined application-level support for OSGI there will be a cleaner solution for sharing application classes.
[Message sent by forum member 'ksak']

http://forums.java.net/jive/thread.jspa?messageID=396697