title: Getting the Java thread id and stack trace of run-away Java thread
body: <p>On my busiest production installation, on occasion I get a single thread that seems to get stuck in an infinite loop.  I've not managed to figure out who is the culprit, after much research and debugging, but it seems like it should be possible.  Here are the gory details:</p>
  
  <p><strong><em>Current debugging notes:</em></strong></p>
  
  <p>1) <strong>ps -eL 18975</strong> shows me the the Linux pid the problem child thread, 19269</p>
  
  <pre><code>$ps -eL | grep 18975
  ...
  PID   LWP   TTY          TIME CMD
  18975 18994 ?        00:00:05 java
  18975 19268 ?        00:00:00 java
  18975 19269 ?        05:16:49 java
  18975 19271 ?        00:01:22 java
  18975 19273 ?        00:00:00 java
  ...
  </code></pre>
  
  <p>2) <strong>jstack -l 18975</strong> says there are no deadlocks, <strong>jstack -m 18975</strong> does not work </p>
  
  <p>3) <strong>jstack -l 18975</strong> does give me the stack trace for all my threads (~400).  Example thread stack (<em>and not the problem</em>):</p>
  
  <pre>"http-342.877.573.944-8080-360" daemon prio=10 tid=0x0000002adaba9c00 nid=0x754c in Object.wait() [0x00000000595bc000..0x00000000595bccb0]
     java.lang.Thread.State: WAITING (on object monitor)
          at java.lang.Object.wait(Native Method)
          - waiting on  (a org.apache.tomcat.util.net.JIoEndpoint$Worker)
          at java.lang.Object.wait(Object.java:485)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.await(JIoEndpoint.java:416)
          - locked  (a org.apache.tomcat.util.net.JIoEndpoint$Worker)
          at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:442)
          at java.lang.Thread.run(Thread.java:619)
  </pre>
  
  <p>4) The ps -eL output's thread ID does not match the output from jstack, or at least I cannot see it.  (jstack documentation is a bit sparse.)  </p>
  
  <p>5) There are no heavy IO, memory usage or other corresponding activity clues to work with.</p>
  
  <p><strong><em>Platform:</em></strong></p>
  
  <ul>
  <li>Java 6</li>
  <li>Tomcat 6</li>
  <li>RHEL 4 (64-bit)</li>
  </ul>
  
  <p>Does anybody know how I can make that connection from the linux ps output to my problem child java thread?  So close, yet so far...</p>