Java - How to map Linux Thread ID to Java Thread ID

When you are looking at Top output, you will something see Java processes eating up CPU. The next question you will ask, what is happening to the Java process? Usually, I will do the following

1) Identify the process

In the following example, I saw CPU usage over 170% of one of the Java process. The process ID is 11795



2) Find out the Linux thread

What next? Let's check the Linux threads within the process. I run

top -H -p 11795

where -H is thread mode and -p is the pid

In the Top output, you will now see the threads that are using the CPU. 11797 and 11798 is the suspicious thread


3) Find out the Java stack trace

Next, you will need the Java stack trace of the troubled process. In this case, you need jstack

I run

jstack 11795 > jstack_output1.txt

the above will print out the Java stack trace to a file.

4) Mapping Linux thread id to Java thread id

This is the most important part. First, if you look at the jstack output, you will see the following


especially, you will see nid=0x???? 

nid mean native thread id - OS
tid mean Java thread id

The remaining thing to do is to map Linux thread id 11797 to Hex value. And Google will tell you it is 0x2E15


Now, if you search the jstack output file, you should see a match in nid. For me, they are


GC task threads that eating the CPU.





Comments

Popular Posts