Hi, > The major problem (and the starting point of the whole thing) > is that when > classes are being loaded the JVM can call > "loadClassInternal()" on multiple > class loaders at the same time. This method is synchronized and so > immediately two different threads have locked two different > class loaders, > let us say Thread A has locked ClassLoader A and Thread B has locked > ClassLoader B.
Also ClassLoader.loadClass(String, boolean) is sync'ed. It's not a problem of loadClassInternal IMHO. Also the UCL at the end calls super.loadClass() (in loadClassLocally()) so... > Now loadClassInternal simply calls the loadClass method of > the respective > class loader and so if you have a class loader (like the JBoss > UnifiedClassLoader) which can delegate to other class loaders (via > UnifiedLoaderRepository) to load classes you can get a situation where > Thread A now wants to access synchronized methods in ClassLoader B and > Thread B wants to access synchronized methods in ClassLoader > A and neither > can because of the earlier locks already gained, hence deadlock. Correct. > This bought about by the fact that the private > "loadClassInternal()" method > is synchronized and can be called pretty much at any time by > the JVM. Not only. It's a startup problem IMHO: until all classes are cached by ULR, you may find that UCL calls super.loadClass() and you have the same problem. > The only way you could work around the problem is if you > could synchronize > on some common object before loadClassInternal is called, but > since this is > called rather unpredictably directly from the JVM I don't > know if there is > any way to do this. > > Why the F*K "loadClassInternal()" is synchronized is a > complete mystery as > all it does is call "loadClass()" which can be synchronized > if it needs to > be. It is sync'ed, and would lead to the same problem, no ? I *think* (but not sure) that loadClass is sync'ed to ensure correct class initialization. If 2 threads go step-by-step in parallel to load the same class with the same CL, somewhere you have to sync to initialize the class only once... I agree that sync'ing so high it's an implementation mistake, they could have sync'ed around shared data structures, as ULR does. Simon _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
