标签:quartz down cpu故障 java程序 浏览器 har read nano run
https://www.jianshu.com/p/d4e31301ba2e
Linux服务器的配置是4核16G,将war包部署到tomcat后,启动tomcat,发现内存占用率不高,但是CPU一直高达100%;浏览器输入相关url也无法访问该项目,且tomcat的进程一直存在,程序的配置什么的都没问题啊,一头雾水......通过top命令查看服务器的性能状况如下:
[root@aws-java-MAM ec2-user]# top
top - 18:49:21 up 45 min, 2 users, load average: 0.97, 0.50, 0.19
Tasks: 129 total, 1 running, 128 sleeping, 0 stopped, 0 zombie
Cpu0 : 95.1%us, 0.0%sy, 0.0%ni, 4.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu1 : 5.9%us, 0.0%sy, 0.0%ni, 94.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu2 : 1.6%us, 0.5%sy, 0.0%ni, 97.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu3 : 1.1%us, 0.0%sy, 0.0%ni, 98.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 16330912k total, 2374776k used, 13956136k free, 20172k buffers
Swap: 0k total, 0k used, 0k free, 370244k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
2141 root 20 0 7684m 1.7g 22m S 103.0 11.0 3:35.95 java
1423 root 20 0 449m 23m 2884 S 0.0 0.1 0:01.05 salt-minion
1959 root 20 0 98280 3860 2920 S 0.0 0.0 0:00.00 sshd
2278 root 20 0 98280 3836 2900 S 0.0 0.0 0:00.00 sshd
1387 postfix 20 0 81536 3436 2544 S 0.0 0.0 0:00.00 qmgr
1379 root 20 0 81284 3424 2520 S 0.0 0.0 0:00.01 master
1386 postfix 20 0 81364 3380 2508 S 0.0 0.0 0:00.00 pickup
1303 ntp 20 0 30720 2124 1508 S 0.0 0.0 0:00.00 ntpd
1986 root 20 0 105m 2000 1544 S 0.0 0.0 0:00.03 bash
1413 zabbix 20 0 42448 1972 1300 S 0.0 0.0 0:00.13 zabbix_agentd
可以看出PID为2141的java进程耗费内存11%,不算高,但是CPU达到103%,应该是哪里出现了死循环或者线程阻塞住了,导致CPU占用居高不下(各种配置个人觉得应该是没问题的),怎么定位到具体线程或者程序位置呢?想到了jstack工具。
jstack是java虚拟机自带的一种堆栈跟踪工具。用于打印出给定的java进程ID或core file或远程调试服务的Java堆栈信息,使用jstack命令工具可以得到线程堆栈信息,根据这些线程堆栈信息,我们可以去检查Java程序出现的问题,如检测死锁,并输出死锁的信息的排查。
[root@aws-java-MAM ec2-user]# ps -mp 2141 -o THREAD,tid,time |sort -rn
USER %CPU PRI SCNT WCHAN USER SYSTEM TID TIME
root 94.3 - - - - - - 00:04:04
root 85.9 19 - - - - 2185 00:03:21
root 3.7 19 - futex_ - - 2153 00:00:09
root 3.6 19 - futex_ - - 2152 00:00:09
root 2.8 19 - futex_ - - 2162 00:00:07
root 1.3 19 - futex_ - - 2154 00:00:03
root 0.9 19 - futex_ - - 2176 00:00:02
root 0.7 19 - futex_ - - 2147 00:00:02
root 0.7 19 - futex_ - - 2146 00:00:02
root 0.7 19 - futex_ - - 2145 00:00:02
root 0.7 19 - futex_ - - 2144 00:00:02
root 0.2 19 - futex_ - - 2148 00:00:00
root 0.2 19 - futex_ - - 2143 00:00:00
root 0.1 19 - inet_s - - 2209 00:00:00
root 0.0 19 - poll_s - - 2181 00:00:00
root 0.0 19 - poll_s - - 2179 00:00:00
root 0.0 19 - futex_ - - 2188 00:00:00
root 0.0 19 - futex_ - - 2183 00:00:00
root 0.0 19 - futex_ - - 2182 00:00:00
root 0.0 19 - futex_ - - 2180 00:00:00
root 0.0 19 - futex_