简体   繁体   中英

what does the lock id mean in java thread dump

I usually observed the lock id (as following) in the thread dump:

"Thread-pool-Bill" - Thread t@42
   java.lang.Thread.State: RUNNABLE
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    - locked <79f0aad8> (a java.net.SocksSocketImpl)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) 

In locked <79f0aad8> (a java.net.SocksSocketImpl) , what does 79f0aad8 mean? It doesn't seem to be an object address nor object id cause I couldn't find it from heap dump. So what it is?

its address of internal lock construct(monitor object) for hotspot JVM.

 code for your reference oop o = _locked_monitors->at(i); instanceKlass* ik = instanceKlass::cast(o->klass()); st->print_cr("\\t- locked <" INTPTR_FORMAT "> (a %s)", (address)o, ik->external_name()); 

You can consider it an opaque identifier. The key is that other pieces of code may be waiting on that particular lock, which will also show up in the thread dump. So you can use it to match up waits and locks between threads. It may also show up in the JVMs thread dump deadlock detection outputs - but I'm not sure.

The entry appears in the stack trace from either a synchronised method, or explicit synchronised block, and is related to the object synchronized on.

Its the hashcode/id of the object on which the Thread owns the lock. Since your thread is RUNNABLE so some other thread may or may not be waiting on it. If another thread is waiting for this lock then your Thread dump would have another entry somewhere else showing a BLOCKED or WAITING Thread which is waiting for lock on the same id ie 79f0aad8

But since you say you cannot find this String (79f0aad8) anywhere else in your file so either:

  • you have multiple thread dump files or
  • the thread Thread t@42 wasn't blocking any other thread when the thread dump was taken.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM