Diagnose High CPU Java Process on Linux
2016-04-18
- Views
If you are running into issue with java process with high CPU utilization, just do below simple steps to get some clue:
Get the PID of the java process that has issue just by
top
Get TID of the threads in the process that consumes a lot of CPU time
ps -Lf [PID]
or
ps H -eo user,pid,ppid,tid,time,%cpu --sort=%cpu | grep [PID]
Get a thread dump by jstack
jstack PID > /var/tmp/thread_dump_[PID].txt
Convert the TID found in step 2 to NID (Oct to Hex)
e.g. 9588 -> 0x2574
Find the NID in the thread dump file and check the stack to see what the thread does
grep [NID] /var/tmp/thread_dump_[PID].txt