I would like to get better understanding of how JVM loads classes.
If for example I instantiate class A in two separate threads that run concurrently. Lets say that class A creates static instance of Hashtable. Will JVM guarantee that both threads will see the same Hashtable or this implementation is broken?
I know that DCL for singleton can be fixed by making instance static:
So does it mean that JVM synchronizes class loaders and only loads one class even if two threads try to instantiate it concurrently(running on 2 CPUs).
The ClassLoading mechanism is definately Thread safe (synchronized).
But be carefull, if you have more than one ClassLoader. You can have the same class loaded twice in different ClassLoaders with different static Object references. A class is unique by its full name and its ClassLoader.