Search code examples
javadesign-patternssingletonclassloader

Singletons in Multiple Classloader and VM cases


How to safely code Singletons in case of two or more Classloaders and VMs. I see this problem explained at: http://java.sun.com/developer/technicalArticles/Programming/singletons/

Solutions ?


Solution

  • If you want share a singleton between ClassLoaders, you have a common parent load the singleton, or you can have each ClassLoader explicitly define which classes Singleton you want that Classloader to use.