1、jps -lmv 查找要分析的java进程
2、查出最耗CPU线程 top -Hp pid ( top -Hp 73838)
126453 root 20 0 16.6g 6.5g 0 S 2.2 20.6 0:19.31 java
126243 root 20 0 16.6g 6.5g 0 S 1.9 20.6 0:26.59 java
84628 root 20 0 16.6g 6.5g 0 S 1.6 20.6 0:08.29 java
118500 root 20 0 16.6g 6.5g 0 S 0.9 20.6 0:32.64 java
126340 root 20 0 16.6g 6.5g 0 S 0.9 20.6 0:20.54 java
126536 root 20 0 16.6g 6.5g 0 S 0.9 20.6 0:25.99 java
84656 root 20 0 16.6g 6.5g 0 S 0.9 20.6 0:07.01 java
90628 root 20 0 16.6g 6.5g 0 S 0.9 20.6 0:00.80 java
75241 root 20 0 16.6g 6.5g 0 S 0.6 20.6 4:23.77 java
75363 root 20 0 16.6g 6.5g 0 S 0.6 20.6 92:06.08 java
5138 root 20 0 16.6g 6.5g 0 S 0.6 20.6 0:19.65 java
90617 root 20 0 16.6g 6.5g 0 S 0.6 20.6 0:00.86 java
3、通过线程ID转换16进制,printf "%x\n" tid
printf "%x\n" 126453 (1edf5)
4、追踪线程内部,查看load过高原因。通过命令: jstack 73838 > /tmp/tinfo.txt,将线程堆里面的信息全部保存下来
5、通过转换的16进制 就可以去tinfo.txt 里面查找对应的线程
"https-jsse-nio-8080-exec-1930" #2459769 daemon prio=5 os_prio=0 tid=0x00007fd288bac000 nid=0x1edf5 waiting on condition [0x00007fd0d8994000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000005d916b4c8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
at org.apache.tomcat.util.threads.TaskQueue.poll(TaskQueue.java:89)
at org.apache.tomcat.util.threads.TaskQueue.poll(TaskQueue.java:33)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
6、jmap 进程id(73838) 得到实例在内存中的使用情况
jmap -histo:live 73838 > /tmp/jmap.txt
more /tmp/jmap.txt |grep hanshow| head -n 100 # 查看前100个
# jstat -gc 1729569
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT CGC CGCT GCT
68608.0 69632.0 0.0 41837.0 1208832.0 394751.0 207360.0 52828.7 96896.0 92920.0 11136.0 10507.6 13 0.625 3 0.469 - - 1.094
# jstat -gcutil 1729569 5000
S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT
0.00 60.08 32.66 25.48 95.90 94.36 13 0.625 3 0.469 - - 1.094
0.00 60.08 32.66 25.48 95.90 94.36 13 0.625 3 0.469 - - 1.094
java jstack和jmap的基本使用
于 2021-03-23 10:04:06 首次发布