JAVA CPU占用情况
1、使用top 命令查看占用高的进程
top
--------------------------------------------------------
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
8600 root 20 0 4899m 2.6g 18m S 162.8 16.8 37:24.54 java
12406 root 20 0 4054m 637m 18m S 101.8 4.0 1:26.44 java
12681 root 20 0 103m 1336 760 R 27.9 0.0 0:01.85 netstat
10907 root 20 0 192m 5720 1312 R 18.9 0.0 34431:06 supervisord
6065 root 20 0 4120m 882m 7836 S 18.2 5.5 294:44.65 java
5775 nginx 20 0 1198m 75m 9184 R 13.6 0.5 11:21.52 nginx
5774 nginx 20 0 1199m 76m 9188 R 12.9 0.5 10:57.19 nginx
...........
2、根据pid 查找占用高的线程
top -H -p
或者
ps -mp -o THREAD,tid,time
ps -mp 6203 -o THREAD,tid,time | awk '{print $2,$8}' | sort -k1 -r | head -n 15
3、将线程id 转换为16进制
printf "%x\n"
4、根据pid 和tid 生成线程快照
jstack |grep -A 30
5、在thread dump中,要留意下面几种状态
Deadlock (重点关注)
死锁
Waiting on condition (重点关注)
等待资源
Waiting on monitor entry (重点关注)
等待获取监视器
Blocked
阻塞
Runnable
执行中
Suspended
暂停
Object.wait() 或 TIMED_WAITING
对象等待中
Parked
停止
使用开源脚本来查看所以Java进程的使用情况
wget --no-check-certificate https://raw.github.com/oldratlee/useful-scripts/release/show-busy-java-threads
chmod +x show-busy-java-threads