How make a Singleton across all ClassLoaders?

 ̄綄美尐妖づ 提交于 2020-01-25 04:11:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!