The first step is to find out the Java process PID:
Grep-v "awk ' {print $2} '
The second step is to find the most CPU -Consuming threads :
PS-MP pid-o Thread,tid,sort-rn-k9
The third step is to convert the TID to a three- input system :
printf "%x\n" tid
The fourth step is to dump the JVM stack information :
Jstack PID
the NID in jstack corresponds to the preceding octal tid, thus finding the most CPU-consuming thread code.
To get a thread using the top command :
TOP-HP PID
Attach a complete script: http://blog.91gaoqing.com/archives/253.html
#!/bin/ShExport lang="Zh_cn. UTF-8"; Export lc_all="Zh_cn. UTF-8"; log_file="/tmp/jmonitor.log"; jstack_file="/tmp/jstack.log"; Pid="$";Shift; i=0; j="$";if [-Z"${J}" ];Thenj=5;FiPs-mp ${pid}-o Thread,tid,Time |Sort-rn >${log_file};jstack ${pid} >${jstack_file};For lineIn 'Cat ${log_file}|Gawk-f‘-‘‘{Print $4}' |Gawk-f‘‘‘{Print $}‘`Doi=$ (($i +1));if (($i > $j));ThenBreakFi; Xpid= ' printf"%x\n"${line} ';Echo-ne"\033[32m"; echo ${xpid}; echo-e "\033[34m"; grep-a "0x${xpid}" ${jstack_file}; echo-e "\e[0m"; Done;
Java Thread Monitoring