Java ClassLoader Deadlock

Leave a comment

August 8, 2012 by huionn

I encountered weird deadlock:

I have read http://www.ibm.com/developerworks/java/library/j-dclp

Found one Java-level deadlock:
=============================
"http-0.0.0.0-8443-3":
  waiting to lock monitor 0x06777d44 (object 0x2479a050, a org.nuxeo.runtime.tomcat.dev.LocalURLClassLoader),
  which is held by "http-0.0.0.0-8443-1"
"http-0.0.0.0-8443-1":
  waiting to lock monitor 0x05d6ff84 (object 0x247371e8, a org.nuxeo.runtime.tomcat.dev.NuxeoDevWebappClassLoader),
  which is held by "http-0.0.0.0-8443-3"

4/index.html and understand the classloading lock issue. What puzzles me is that org.nuxeo.runtime.tomcat.dev.NuxeoDevWebappClassLoader does not hold lock in the code. I cannot find any possibility that the lock is hold.

@Override
    public Class loadClass(String name, boolean resolve)
            throws ClassNotFoundException {
        try {
            synchronized (this) {
                return super.loadClass(name, resolve);
            }
        } catch (ClassNotFoundException e) {
            for (LocalClassLoader cl : getChildren()) {
                try {
                    return cl.loadLocalClass(name, resolve);
                } catch (ClassNotFoundException ee) {
                    // do nothing
                }
            }
        }
        throw new ClassNotFoundException(name);
    }

Then, finally I found that the lock is hold implicitly by JVM in class loader native code (likely to be vm/classfile/systemDictionary.cpp). In addition, this is a known issue for cyclic class loader delegation model. There is improvement in Java 7 that mitigate this issue: http://docs.oracle.com/javase/7/docs/technotes/guides/lang/cl-mt.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: