Singletons in Multiple Classloader and VM cases?

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.

– Ved Jul 29 at 12:02 hmmm. Not sure if this will help, but here is an example loading and unloading classloaders.Vanillajava.blogspot.Com/2011/07/… To share a singleton, you need to make the class accessible to the parent Classloader, so it loads it. You can override the loadClass method to if want to be selective on a per class loader basis.

– Peter Lawrey Jul 29 at 12:40.

The article clearly states that distributed applications should stay away from Singletons. Any particular problem you are trying to solve here? Also, for singletons which hold true constants which are never modified during the application run, multiple "instances" of your "singleton" shouldn't pose a problem.In other cases, you are better off injecting your configuration (the dependency injection way of doing things) in the classes which need it.

Yes, I agree with what you say. I am not trying to solve a specific problem but this was rather a theoretical question – Ved Jul 29 at 12:01.

1) network socket survives multiple VMs Port busy 8765 java.net. BindException: Address already in use 2) so does file WARNING: Creating a new instance of CacheManager using the diskStorePath safely code Singletons in case of two or more Classloaders and VMs based on these resources (if you really badly need to stick with this anti-pattern).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions