1. 确定占用cpu高的线程id:
方法一: 直接使用 ps Hh -eo pid,tid,pcpu | sort -nk3 |tail 获取对于的进程号和线程号,然后跳转到3.
方法二: . 查看哪个进程线程占用cpu过高; top / ps -aux, 获得进程号
. 确定哪个线程占用cpu过高,进入进程号的目录:/proc/pid/task,
执行:grep SleepAVG **/status | sort -k2,2 | head, 确定cpu占用较高的线程号。
2.使用:jstack pid, 或者kill -3 pid 会打印线程堆栈的情况。 jstack输出到当前命令的标准输出,kill -3 输出到当前进程jvm的标准输出。根据第二步中获取的线程号,查询堆栈中正在执行的代码。输出示例如下:
Thread 2060: (state = BLOCKED)
- java.lang.Object.wait(long) @bci=0 (Compiled frame; information may be imprecise)
Error occurred during stack walking:
Thread 2059: (state = IN_NATIVE)
- java.net.PlainSocketImpl.socketAccept(java.net.SocketImpl) @bci=0 (Interpreted frame)
- java.net.PlainSocketImpl.accept(java.net.SocketImpl) @bci=7, line=384 (Interpreted frame)
- java.net.ServerSocket.implAccept(java.net.Socket) @bci=50, line=450 (Interpreted frame)
- java.net.ServerSocket.accept() @bci=48, line=421 (Interpreted frame)
- org.apache.jk.common.ChannelSocket.accept(org.apache.jk.core.MsgContext) @bci=46, line=293 (Interpret
ed frame)
- org.apache.jk.common.ChannelSocket.acceptConnections() @bci=68, line=647 (Interpreted frame)
- org.apache.jk.common.ChannelSocket$SocketAcceptor.runIt(java.lang.Object[]) @bci=4, line=857 (Interpr
eted frame)
- org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run() @bci=167, line=684 (Interpreted frame
)