使用top -Hp命令查看某进程里面,资源占用率高的线程id。通过Java自带的jstack命令查看线程id中锁死的代码行。
排查步骤
- 找到出现问题的进程
top 命令,大写M(按照进程占用内存排序),大写P(按照进程占用CPU排序)
或ps -ef|grep keyword
- top -Hp pid 查看占用最多资源的线程
-
把线程pid转换成16进制数
这里我们看到的占用最多资源的线程是:3440
使用命令printf “%x\n” 3440 把线程pid转换成16进制数,得到:d70。
-
利用jstack命令查看此进程的快照信息
使用jstack 3429 | grep -20 d70命令查询该线程阻塞的地方
jstack命令
作用:生成JVM当前时刻线程的快照(threaddump,即当前进程中所有线程的信息)
目的:帮助定位程序问题出现的原因,如长时间停顿、CPU占用率过高等
top命令
-**H **:Threads-mode operation
Instructs top to display individual threads. Without this
command-line option a summation of all threads in each process
is shown. Later this can be changed with the `H' interactive
command.
-**p **:Monitor-PIDs mode as: **-pN1 -pN2 … **or -pN1,N2,N3 .
jstat查看gc信息
jstat -gcutil 21891 250 7
This example attaches to lvmid 21891 and takes 7 samples at 250 millisecond intervals and displays the output as specified by the -gcutil option.