Which Java Thread is using CPU on Linux?
More for my own reference than anything else, a means to establish which java thread is using CPU time on Linux.
- Get the process ID (PID) using
ps -ef
- Enter the command
top -p<pid>
- Press shift-h
- All threads in the parent java process should start to appear with their lightweight process IDs and CPU usage - this takes some time
- Now send a
kill -3 <pid>
to the process - this will trigger a thread dump without ending the process.CTL-\
will also work if you have java running in a console. - Convert the PIDs of the lightweight process you are interested in into hex (so 2042 = 0x7FA)
- Find the file where the Java process was sending system.out and grep for
nid=<lightweight pid in hex>
Bingo, you should have the thread name and stack of the thread using up CPU time