jstack 线程转储是否一致?

Is jstack thread dump consistent?

我从 jstack 获得了线程转储。 它表明两个线程锁定在同一个对象 locked <0x00000000c0313ce0> 上。 当 jstack 显示第一个线程的堆栈跟踪而不是在同一时刻显示第二个线程的堆栈跟踪时,是否可能出现这种情况? 或者还有什么可能导致这种锁定情况?

"Thread-1" #44 prio=5 os_prio=0 tid=0x000000001c418800 nid=0x922c in Object.wait() [0x0000000018ffe000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at org.h2.mvstore.db.MVTable.doLock1(MVTable.java:242)
    at org.h2.mvstore.db.MVTable.lock(MVTable.java:167)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.engine.Database.lockMeta(Database.java:896)
    at org.h2.engine.Database.removeMeta(Database.java:919)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.table.Table.removeChildrenAndResources(Table.java:525)
    at org.h2.mvstore.db.MVTable.removeChildrenAndResources(MVTable.java:799)
    at org.h2.engine.Session.cleanTempTables(Session.java:830)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.engine.Session.close(Session.java:708)
    at org.h2.engine.Database.closeAllSessionsException(Database.java:1186)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.engine.Database.close(Database.java:1224)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.engine.DatabaseCloser.run(DatabaseCloser.java:63)

"Resource Destroyer in BasicResourcePool.close()" #110 daemon prio=5 os_prio=0 tid=0x000000001c41a000 nid=0x2d44 in Object.wait() [0x000000001b6ae000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    at org.h2.mvstore.db.MVTable.doLock1(MVTable.java:242)
    at org.h2.mvstore.db.MVTable.lock(MVTable.java:167)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.engine.Database.lockMeta(Database.java:896)
    at org.h2.engine.Database.removeMeta(Database.java:919)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.table.Table.removeChildrenAndResources(Table.java:525)
    at org.h2.mvstore.db.MVTable.removeChildrenAndResources(MVTable.java:799)
    at org.h2.engine.Session.cleanTempTables(Session.java:830)
    - locked <0x00000000c0313ce0> (a org.h2.engine.Database)
    at org.h2.engine.Session.close(Session.java:708)
    at org.h2.jdbc.JdbcConnection.close(JdbcConnection.java:383)
    - locked <0x00000000ede38ce0> (a org.h2.engine.Session)
    - locked <0x00000000ede37708> (a org.h2.jdbc.JdbcConnection)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:642)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeMaybeCheckedOut(NewPooledConnection.java:255)
    - locked <0x00000000ee186430> (a com.mchange.v2.c3p0.impl.NewPooledConnection)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolPooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:621)
    - locked <0x00000000ee186490> (a java.lang.Object)
    at com.mchange.v2.resourcepool.BasicResourcePoolDestroyResourceTask.run(BasicResourcePool.java:1065)
    at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1090)
    at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1051)
    at com.mchange.v2.resourcepool.BasicResourcePool.access0(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool.run(BasicResourcePool.java:1305)

这两个线程没有锁定对象:它们都在等待对同一个对象的 o.wait() 调用 o

记住,o.wait()首先释放对象o的锁。然后它等待其他一些线程通知该对象,然后在re-acquires锁定之前返回给调用者。