1

I've tried all the suggested solutions including:

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?

Community
  • 1
  • 1
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
  • 1
    If you can't put the class on the system classpath then I believe you will ALWAYS have a race condition in the case where the singleton is being instantiated by multiple threads at the same time. There has to be something in a known root position that can be identified statically to serve as the anchor, or at least a monitor to prevent the race condition. – Jim Garrison Jun 19 '16 at 22:26
  • Why do you need that? What is the problem here? – marcospereira Jun 19 '16 at 22:27
  • Is this a duplicate of [How make an object that's shared across the entire application in play framework (1.x)?](http://stackoverflow.com/questions/37909439/how-make-an-object-thats-shared-across-the-entire-application-in-play-framework) – marcospereira Jun 19 '16 at 22:28
  • why is it an issue to have it in the Extensions ClassLoader? For me it is the only way – Nicolas Filotto Jun 19 '16 at 22:36
  • @NicolasFilotto How do you programmatically load it there? or do you put the classes in that directory? – Don Rhummy Jun 20 '16 at 00:10
  • put your jar in JAVA_HOME/jre/lib/ext – Nicolas Filotto Jun 20 '16 at 03:05

0 Answers0