在LINUX系統(tǒng)中排查JAVA程序CPU占用過高問題
????????首先使用top命令,來監(jiān)控linux的系統(tǒng)狀況(實(shí)時(shí)顯示系統(tǒng)中各個(gè)進(jìn)程的資源占用情況)。

PID:?Process ID.
USER:?The owner of the process.
PR:?Process priority.
NI:?The nice value of the process.
VIRT:?Amount of virtual memory used by the process.
RES:?Amount of resident memory used by the process.
SHR:?Amount of shared memory used by the process.
S:?Status of the process.
%CPU:?The share of CPU time used by the process since the last update.
%MEM:?The share of physical memory used.
TIME+:?Total CPU time used by the task in hundredths of a second.
COMMAND:?The command name or command line (name + options).
????????尤其注意一下這個(gè)CPU時(shí)間占用百分比(%CPU),如果某個(gè)進(jìn)程高了,就用“顯示當(dāng)前進(jìn)程的狀態(tài)”的命令去查看,這個(gè)命令類似于Windows操作系統(tǒng)的任務(wù)管理器:
????????ps -mp pid -o THREAD,tid,time

????????觀察并分析一下%CPU和TIME這兩個(gè)參數(shù),如果占比過高,那么使用Java堆棧跟蹤工具去打印相關(guān)進(jìn)程的信息:
????????jstack pid

????????16進(jìn)制可以使用命令 printf "%x\n" pid 來實(shí)現(xiàn)。每個(gè)線程都有一個(gè)nid,我們找到對(duì)應(yīng)的nid。
????????這樣子可以顯示出比較詳細(xì)的代碼信息,再去定位到源碼位置分析。