Missing threads in a Java thread dump
<p>I use <code>ThreadMXBean</code> to report a list of threads using <code>dumpAllThreads(true, true)</code>:</p>

<pre><code>ThreadMXBean bean = ManagementFactory.getThreadMXBean();
for (ThreadInfo info : bean.dumpAllThreads(true, true)) {
    writer.append(ThreadInfos.toStringFull(info));
}
</code></pre>

<p>However, some of the threads in the dump don't appear to exist, and worse they appear to own monitors!:</p>

<pre><code>"pool-24-thread-16" Id=99 WAITING on java.util.concurrent.locks.ReentrantLock$NonfairSync@a8bb29 owned by "ForkJoinPool-2-worker-13" Id=114
        at sun.misc.Unsafe.park(Native Method)
        -  waiting on java.util.concurrent.locks.ReentrantLock$NonfairSync@a8bb29
        at java.util.concurrent.locks.LockSupport.park(Unknown Source)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(Unknown Source)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(Unknown Source)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(Unknown Source)
        at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(Unknown Source)
        at java.util.concurrent.locks.ReentrantLock.lock(Unknown Source)
</code></pre>

<p>In this example, <code>ForkJoinPool-2-worker-13</code> is not listed in the thread dump, so it's difficult to see how it has grabbed <code>ReentrantLock$NonfairSync@a8bb29</code>.</p>

<p>I must be making some silly mistake! How do I find how these threads have taken these locks?</p>