Thread deadlock analysis
"waiting for monitor entry [0x00007f0e2bbfa000]" the hexadecimal address does not correspond directly with lock addresses.
Test code:
public class ThreadMonitorTest implements Runnable
{
ThreadMonitorTest b;
public static void main(String[] args)
{
ThreadMonitorTest a = new ThreadMonitorTest();
a.b = new ThreadMonitorTest();
a.b.b = a;
new Thread(a).start();
new Thread(a.b).start();
}
public void run()
{
synchronized(this) {
try
{
this.wait(60000);
synchronized (b)
{
b.wait(60000);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
Stacktraces taken while the above test program was executing.
---------------------------------------------------------------------------------
Immediately after starting, timed waiting.
Thread-1" prio=10 tid=0x00007f0e48114000 nid=0x256e in Object.wait() [0x00007f0e2bbfa000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:20)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0" prio=10 tid=0x00007f0e48112000 nid=0x256d in Object.wait() [0x00007f0e2bcfb000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d278> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:20)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
---------------------------------------------------------------------------------
After 1 minute, still time waiting.
Event though the below is a deadlock, the JVM doesn't flag it until the timed wait expires.
"Thread-1" prio=10 tid=0x00007f0e48114000 nid=0x256e waiting for monitor entry [0x00007f0e2bbfa000]
java.lang.Thread.State: BLOCKED (on object monitor)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- waiting to lock <0x00000007d704d278> (a ThreadMonitorTest)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0" prio=10 tid=0x00007f0e48112000 nid=0x256d in Object.wait() [0x00007f0e2bcfb000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
---------------------------------------------------------------------------------
After two minutes and all timed waits have expired.
"Thread-1" prio=10 tid=0x00007f0e48114000 nid=0x256e waiting for monitor entry [0x00007f0e2bbfa000]
java.lang.Thread.State: BLOCKED (on object monitor)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- waiting to lock <0x00000007d704d278> (a ThreadMonitorTest)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0" prio=10 tid=0x00007f0e48112000 nid=0x256d waiting for monitor entry [0x00007f0e2bcfb000]
java.lang.Thread.State: BLOCKED (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x00007f0e08005ed0 (object 0x00000007d704d278, a ThreadMonitorTest),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x00007f0e08003620 (object 0x00000007d704d288, a ThreadMonitorTest),
which is held by "Thread-1"
Java stack information for the threads listed above:
===================================================
"Thread-1":
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- waiting to lock <0x00000007d704d278> (a ThreadMonitorTest)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0":
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
Found 1 deadlock.
Test code:
public class ThreadMonitorTest implements Runnable
{
ThreadMonitorTest b;
public static void main(String[] args)
{
ThreadMonitorTest a = new ThreadMonitorTest();
a.b = new ThreadMonitorTest();
a.b.b = a;
new Thread(a).start();
new Thread(a.b).start();
}
public void run()
{
synchronized(this) {
try
{
this.wait(60000);
synchronized (b)
{
b.wait(60000);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
Stacktraces taken while the above test program was executing.
---------------------------------------------------------------------------------
Immediately after starting, timed waiting.
Thread-1" prio=10 tid=0x00007f0e48114000 nid=0x256e in Object.wait() [0x00007f0e2bbfa000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:20)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0" prio=10 tid=0x00007f0e48112000 nid=0x256d in Object.wait() [0x00007f0e2bcfb000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d278> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:20)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
---------------------------------------------------------------------------------
After 1 minute, still time waiting.
Event though the below is a deadlock, the JVM doesn't flag it until the timed wait expires.
"Thread-1" prio=10 tid=0x00007f0e48114000 nid=0x256e waiting for monitor entry [0x00007f0e2bbfa000]
java.lang.Thread.State: BLOCKED (on object monitor)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- waiting to lock <0x00000007d704d278> (a ThreadMonitorTest)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0" prio=10 tid=0x00007f0e48112000 nid=0x256d in Object.wait() [0x00007f0e2bcfb000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
---------------------------------------------------------------------------------
After two minutes and all timed waits have expired.
"Thread-1" prio=10 tid=0x00007f0e48114000 nid=0x256e waiting for monitor entry [0x00007f0e2bbfa000]
java.lang.Thread.State: BLOCKED (on object monitor)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- waiting to lock <0x00000007d704d278> (a ThreadMonitorTest)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0" prio=10 tid=0x00007f0e48112000 nid=0x256d waiting for monitor entry [0x00007f0e2bcfb000]
java.lang.Thread.State: BLOCKED (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
Found one Java-level deadlock:
=============================
"Thread-1":
waiting to lock monitor 0x00007f0e08005ed0 (object 0x00000007d704d278, a ThreadMonitorTest),
which is held by "Thread-0"
"Thread-0":
waiting to lock monitor 0x00007f0e08003620 (object 0x00000007d704d288, a ThreadMonitorTest),
which is held by "Thread-1"
Java stack information for the threads listed above:
===================================================
"Thread-1":
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- waiting to lock <0x00000007d704d278> (a ThreadMonitorTest)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
"Thread-0":
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d704d288> (a ThreadMonitorTest)
at ThreadMonitorTest.run(ThreadMonitorTest.java:23)
- locked <0x00000007d704d288> (a ThreadMonitorTest)
- locked <0x00000007d704d278> (a ThreadMonitorTest)
at java.lang.Thread.run(Thread.java:722)
Found 1 deadlock.
Comments