5

Can some one explain me why in stacktrace of hotspot captured by jstack, I see a thread being blocked without any information about lock record by mean what is 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 at ... removed because it is not relevant

Huy Le
  • 1,042
  • 9
  • 10

1 Answers1

0

Somewhere in that stack, in the part you've cut off, is something like:

- waiting to lock <0xa3cd2188> (a java.lang.Object)

Try this simple app, which has a thread print out which thread it's about to wait on, and then waits on it for a while. You can then kill -3 <pid> it (on linux) to get its full thread dump, including all 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!");
        }   
    }   
} 
yshavit
  • 42,327
  • 7
  • 87
  • 124
  • hopefully in other traces you'll be able to see what has obtained the lock on 0x4e619000 – Paul Jowett Mar 08 '12 at 09:28
  • the stacktrace in your example show clearly the what block the thread you will see a line like that `waiting to lock <7f31026a8> (a java.lang.Object)` in stacktrace of a thread – Huy Le Mar 08 '12 at 20:20
  • 2
    If it existed, that "waiting to lock" line would be the line immediately following the top frame in the thread dump, right after the `forName0()` call. But it's not there, as it should be. That is the whole point of this question: why is it missing? – erickson Dec 04 '13 at 21:52
  • @erickson Ah, good point. I googled a bit and found [another SO question](http://stackoverflow.com/questions/7067058) which identified the same problem. Looks like it may be a bug due to too much stress on memory. – yshavit Dec 04 '13 at 22:16
  • In your example, you get threads in WAITING status, but not in BLOCKED as in question. – Andrii Andriichuk Feb 24 '15 at 10:47