问题
I've tried all the suggested solutions including:
- http://snehaprashant.blogspot.com/2009/01/singleton-pattern-in-java.html
- How to create a JVM-global Singleton?
But none of these seem to work. They either are not truly Singletons across all ClassLoaders (the first link above) and result in different instances on application reload (I'm using Play Framework 1.3.x which reloads classes upon code change and recompile), or they require the classes to be on the System classpath.
Is there a solution for this? I want the class to be loaded once and even after classes are reloaded with new ClassLoaders, to still have the same one instance of that class.
Is this possible?
来源:https://stackoverflow.com/questions/37912302/how-make-a-singleton-across-all-classloaders