Java ClassLoader Deadlock

Leave a comment

August 8, 2012 by huionn

I encountered weird deadlock:

I have read

Found one Java-level deadlock:
  waiting to lock monitor 0x06777d44 (object 0x2479a050, a,
  which is held by "http-"
  waiting to lock monitor 0x05d6ff84 (object 0x247371e8, a,
  which is held by "http-"

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

    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:


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: