问题
It is said that Singleton is always on per JVM basis, but somebody asked me to create a singleton instance throughout multiple JVMs. I have found a solution to create an object on one JVM, register it with the JNDI, and lookup that object on different JVMs.
Please share your insight on this.
回答1:
My insight is that it won't work.
Even if you lookup the singleton using JNDI and then use it, the singleton will effectively be created on the JVM you are using as well.
Only way is to just invoke methods on that singleton bean remotely. May be via something like RMI.
来源:https://stackoverflow.com/questions/16525798/singleton-on-multiple-jvms-using-jndi