Java stacktrace shows a blocked thread with no information about what is blocking it
Can someone explain to me why in the hotspot stacktrace captured by jstack I can see the thread is blocked without any information about the lock write blocking it.
3 "ajp-0.0.0.0-8029-1082" daemon prio=10 tid=0x63721000 nid=0x2cba
waiting for monitor entry [0x4e619000]
4 java.lang.Thread.State: BLOCKED (on object monitor)
5 at java.lang.Class.forName0(Native Method)
6 at java.lang.Class.forName(Class.java:186)
7 at com.my.security.SecurityMethodInterceptor$Rule.isAllowed(SecurityMethodInterceptor.java:102)
8 at com.my.security.SecurityMethodInterceptor.isAllowed(SecurityMethodInterceptor.java:163)
9 at com.my.security.SecurityMethodInterceptor.invoke(SecurityMethodInterceptor.java:140)
10 in ... deleted because it is not relevant
+3
source to share
1 answer
Somewhere in this stack, in the part you cut off, there is something like:
- waiting to lock <0xa3cd2188> (a java.lang.Object)
Try this simple app, which has a thread printed on the thread that it waits for and then waits for a while. You can kill -3 <pid>
(on linux) get a complete dump of a thread, including all the stacks, including the stack for the waiting thread.
public class TTest {
public static void main(String[] args) throws Exception {
final Object lock = new Object();
Thread thread = new Thread() {
@Override
public void run() {
System.out.println("Locking on: " + Integer.toString(lock.hashCode(), 16));
synchronized (lock) {
System.out.println("Hello, world!");
}
}
};
synchronized (lock) {
thread.start();
Thread.sleep(600 * 1000);
System.out.println("bye!");
}
}
}
+1
source to share