Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the JVM thread name/id through the known PID/TID

Tags:

java

jvm

tomcat

Yesterday we had a weird problem with our tomcat 6 server which is running on Debian: We had second long freezes/outages that increased in length over time. In the frozen periods all our independent web apps were unresponsive. The outages had a very high regularity and over the course of one hour the outage phases became longer than the active phases, until we restarted the server which solved the problem. Now we want to find out what it was or find a solution to find out what it is if it happens again!

During each outage phase one of the 24 cores was used 100% by one of the tomcat threads, so we assume whatever that thread was doing was freezing the whole tomcat. Sadly we have no idea what that thread was working on. Today I researched a solution to get the TID of a java thread and I found a wonderful solution: Obtaining the thread ID for Java threads in Linux .

Putting it in our extensive log file entries and finding the JVM thread would be easy enough, but what if it's a thread that isn't exactly under our control? And what about the annoyance of having a synced TID / Java-Thread-ID snapshot? This leads to my core question:

Is there a way to get the JVM Thread name/id from a known Linux TID?

My hopes are small, but maybe there is a cross process call to the JVM or another idea I haven't considered yet.

We have the Yourkit profiler running on that server, but during the outage phases it wasn't able to record anything, so we couldn't find the offending thread.

like image 350
ASA Avatar asked Dec 20 '22 10:12

ASA


1 Answers

Use jstack <PID>

"Thread-0" prio=10 tid=0x00002aaab01c3800 nid=0x246d runnable [0x00000000423c7000]
    ^ name             ^ Java thread id       ^ native (OS) thread id
like image 93
apangin Avatar answered Jan 18 '23 23:01

apangin