linux 排查java cpu过高问题

1.查看cpu过高的进程 

[root@localhost ~]# top -c

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
23657 200       20   0 6307604   2.8g   6660 S   1.7 18.2   4981:48 /opt/java/bin/java -server -Dinstall4j.jvmDir=/opt/java -Dexe4j.moduleName=/opt/sonatyp+
16159 root      20   0 7939008   4.6g  11896 S   1.0 29.4   2838:29 java -Duser.home=/var/jenkins_home -Duser.timezone=Asia/Shanghai -Djenkins.model.Jenkin+
 1192 root      20   0   10.1g  28764   4668 S   0.7  0.2   2176:46 /usr/bin/etcd --enable-v2                                                               
  515 polkitd   20   0  214792   8144   5200 S   0.3  0.1   0:00.21 postgres: sonar sonar 172.31.0.3(41318) idle                                            
  940 root      20   0  162292   2508   1680 R   0.3  0.0   0:00.04 top -c                                                                                  
 1391 mysql     20   0 1556220 200396   6320 S   0.3  1.2 250:43.65 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid                      
14016 rduser    20   0 6633960 400536   1832 S   0.3  2.5 713:22.96 GerritCodeReview -jar /var/gerrit/gerrit.war daemon -d /var/gerrit/review_site --consol+
25236 root      20   0 7802068 175444  12124 S   0.3  1.1  16:18.66 java -jar remoting.jar -workDir /opt/work/jenkins/data -jar-cache /opt/work/jenkins/dat+
30730 polkitd   20   0 7875352 199328   4792 S   0.3  1.2 687:38.96 java -jar lib/sonar-

2.查看23657进程的线程有哪些且哪些占用高

进程号:23657 为列子

[root@localhost ~]# ps H -eo pid,tid,%cpu |grep 23657
23657 23657  0.0
23657 24714  0.0
23657 24719  0.0
23657 24720  0.0
23657 24721  0.0
23657 24722  0.0
23657 24723  0.0
23657 24724  0.0
23657 24725  0.0
23657 24741  0.0
23657 24742  0.0
23657 24743  0.0
23657 24744  0.0
23657 24745  0.0

3.  进程号:23657 转好为16进制

[root@localhost ~]# printf "%x\n" 26130
6612

4. 查看代码哪里出现出问题 看前20行 


[root@localhost ~]# jstack 线程号|grep 进程16进制 -A20


[root@localhost ~]# jstack 23657  |grep 6612 -A20

https://github.com/oldratlee/useful-scripts/blob/dev-2.x/docs/java.md

你可能感兴趣的:(linux,java,运维)