目录
吞吐量:用户代码执行时间 /(用户代码执行时间 + 垃圾回收时间)
响应时间:STW越短,响应时间越好
所谓调优,首先确定,追求啥?吞吐量优先,还是响应时间优先?还是在满足一定的响应时间的情况下,要求达到多大的吞吐量...
吞吐量:科学计算、数据挖掘;吞吐量优先的一般:(PS+PO)
响应时间:网站 GUI API(1.8 G1)
根据需求进行JVM规划和预调优
优化运行JVM运行环境(慢,卡顿)
解决JVM运行过程中出现的各种问题(OOM)
调优,从业务场景开始,没有业务场景的调优都是耍流氓
无监控(压力测试,能看到结果),不调优
步骤:
熟悉业务场景(没有最好的垃圾回收器,只有最合适的垃圾回收器)
响应时间、停顿时间 [CMS G1 ZGC] (需要给用户作响应)
吞吐量 = 用户时间 /( 用户时间 + GC时间) [PS]
选择垃圾回收器组合
计算内存需求(经验值 1.5G 16G)
选定CPU(越高越好)
设定年代大小、升级年龄
设定日志参数
- -Xloggc:/opt/xxx/logs/xxx-xxx-gc-%t.log -XX:+UseGCLogFileRotation
- -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20M -XX:+PrintGCDetails
- -XX:+PrintGCDateStamps -XX:+PrintGCCause
或者每天产生一个日志文件
7.观察日志情况
案例1:垂直电商,最高每日百万订单,处理订单系统需要什么样的服务器配置?
1小时360000集中时间段, 100个订单/秒,(找一小时内的高峰期,1000订单/秒)
计算:一个订单产生需要多少内存?512K * 1000 500M内存
案例2:12306遭遇春节大规模抢票应该如何支撑?
12306应该是中国并发量最大的秒杀网站:号称并发量100W最高
CDN -> LVS -> NGINX -> 业务系统 -> 每台机器1W并发(10K问题) 100台机器
普通电商订单 -> 下单 ->订单系统(IO)减库存 ->等待用户付款
12306的一种可能的模型: 下单 -> 减库存 和 订单(redis kafka) 同时异步进行 ->等付款
减库存最后还会把压力压到一台服务器
可以做分布式本地库存 + 单独服务器做库存均衡
大流量的处理方法:分而治之
案例3:有一个50万PV的资料类网站(从磁盘提取文档到内存)原服务器32位,1.5G 的堆,用户反馈网站比较缓慢,因此公司决定升级,新的服务器为64位,16G 的堆内存,结果用户反馈卡顿十分严重,反而比以前效率更低了
案例4:系统CPU经常100%,如何调优?(面试)
CPU100%那么一定有线程在占用系统资源,
1. 找出哪个进程cpu高(top)
2. 该进程中的哪个线程cpu高(top -Hp)
3. 导出该线程的堆栈 (jstack)
4. 查找哪个方法(栈帧)消耗时间 (jstack)
5. 工作线程占比高 | 垃圾回收线程占比高
案例5:系统内存飙高,如何查找问题?(面试)
1. 导出堆内存 (jmap)
2. 分析 (jhat jvisualvm mat jprofiler ... )
案例6:如何监控JVM
1.jstat jvisualvm jprofiler arthas top...
案例7:如果有一个系统,内存一直消耗不超过10%,但是观察GC日志,发现FGC总是频繁产生,会是什么引起的?
代码中显式调用System.gc();
Linux安装JDK1.8
1、测试程序
- package com.lwz.jvm;
-
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.concurrent.ScheduledThreadPoolExecutor;
- import java.util.concurrent.ThreadPoolExecutor;
- import java.util.concurrent.TimeUnit;
-
- /**
- * 从数据库中读取信用数据,套用模型,并把结果进行记录和传输
- */
- public class T15_FullGC_Problem01 {
-
- private static class CardInfo {
- BigDecimal price = new BigDecimal(0.0);
- String name = "张无忌";
- int age = 5;
- Date birthdate = new Date();
-
- public void m() {
-
- }
- }
-
- private static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(50,
- new ThreadPoolExecutor.DiscardOldestPolicy());
-
- public static void main(String[] args) throws Exception {
- executor.setMaximumPoolSize(50);
-
- for (;;){
- modelFit();
- Thread.sleep(100);
- }
- }
-
- private static void modelFit(){
- List
taskList = getAllCardInfo(); - taskList.forEach(info -> {
- // do something
- executor.scheduleWithFixedDelay(() -> {
- //do sth with info
- info.m();
-
- }, 2, 3, TimeUnit.SECONDS);
- });
- }
-
- private static List
getAllCardInfo(){ - List
taskList = new ArrayList<>(); -
- for (int i = 0; i < 100; i++) {
- CardInfo ci = new CardInfo();
- taskList.add(ci);
- }
-
- return taskList;
- }
- }
2、把这个程序拷贝到linux中带文件夹com/lwz/jvm/T15_FullGC_Problem01.java
编译+执行,跑10-18分钟出现Full GC
- [root@localhost java]# ls
- arthas jdk1.8.0_202 jdk-21.0.1_linux-x64_bin.tar.gz
- com jdk-21.0.1 jdk-8u202-linux-x64.tar.gz
- [root@localhost java]# javac com/lwz/jvm/T15_FullGC_Problem01.java
- [root@localhost java]# java -Xms200M -Xmx200M -XX:+PrintGC com.lwz.jvm.T15_FullGC_Problem01
- [GC (Allocation Failure) 51712K->1112K(196608K), 0.0050199 secs]
- [GC (Allocation Failure) 52824K->23134K(196608K), 0.0461103 secs]
- [GC (Allocation Failure) 74846K->54592K(196608K), 0.0757565 secs]
- [GC (Allocation Failure) 106304K->90348K(196608K), 0.0851281 secs]
- [GC (Allocation Failure) 142060K->125204K(195584K), 0.0853713 secs]
- [Full GC (Ergonomics) 125204K->124016K(195584K), 0.7675142 secs]
- [Full GC (Ergonomics) 174704K->156146K(195584K), 0.4488494 secs]
- [Full GC (Ergonomics) 187391K->176629K(195584K), 0.3849072 secs]
- [Full GC (Ergonomics) 187391K->182317K(195584K), 0.4127277 secs]
- [Full GC (Ergonomics) 187391K->185019K(195584K), 0.3578134 secs]
- [Full GC (Ergonomics) 187391K->186352K(195584K), 0.4031946 secs]
- [Full GC (Ergonomics) 187183K->186540K(195584K), 0.3632300 secs]
- [Full GC (Allocation Failure) 186540K->186540K(195584K), 0.3203676 secs]
- Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
- at java.lang.reflect.Array.newArray(Native Method)
- at java.lang.reflect.Array.newInstance(Array.java:75)
- at java.util.Arrays.copyOf(Arrays.java:3212)
- at java.util.Arrays.copyOf(Arrays.java:3181)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.grow(ScheduledThreadPoolExecutor.java:921)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1014)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1037)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:328)
- at java.util.concurrent.ScheduledThreadPoolExecutor.scheduleWithFixedDelay(ScheduledThreadPoolExecutor.java:597)
- at com.lwz.jvm.T15_FullGC_Problem01.lambda$modelFit$1(T15_FullGC_Problem01.java:43)
- at com.lwz.jvm.T15_FullGC_Problem01$$Lambda$1/1418481495.accept(Unknown Source)
- at java.util.ArrayList.forEach(ArrayList.java:1257)
- at com.lwz.jvm.T15_FullGC_Problem01.modelFit(T15_FullGC_Problem01.java:41)
- at com.lwz.jvm.T15_FullGC_Problem01.main(T15_FullGC_Problem01.java:34)
- [Full GC (Ergonomics) 187104K->186536K(195584K), 0.3286528 secs]
- [Full GC (Allocation Failure) 186536K->186536K(195584K), 0.3276186 secs]
- [Full GC (Ergonomics) 186536K->186536K(195584K), 0.3817908 secs]
- [Full GC (Allocation Failure) 186536K->186536K(195584K), 0.3237639 secs]
- Exception in thread "pool-1-thread-41" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186547K->186538K(195584K), 0.3503159 secs]
- [Full GC (Allocation Failure) 186538K->186538K(195584K), 0.3146940 secs]
- at java.lang.reflect.Array.newArray(Native Method)
- at java.lang.reflect.Array.newInstance(Array.java:75)
- at java.util.Arrays.copyOf(Arrays.java:3212)
- at java.util.Arrays.copyOf(Arrays.java:3181)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.grow(ScheduledThreadPoolExecutor.java:921)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1014)[Full GC (Ergonomics) 186553K->186540K(195584K), 0.3524864 secs]
- [Full GC (Allocation Failure) 186540K->186540K(195584K), 0.3175467 secs]
-
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1037)
- [Full GC (Ergonomics) 186548K->186540K(195584K), 0.3627384 secs]
- [Full GC (Allocation Failure) 186540K->186540K(195584K), 0.3246809 secs]
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ScheduledThreadPoolExecutor.reExecutePeriodic(ScheduledThreadPoolExecutor.java:346)
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:296)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
- Exception in thread "pool-1-thread-47" java.lang.OutOfMemoryError: Java heap space
- Exception in thread "pool-1-thread-29" java.lang.OutOfMemoryError: Java heap space
- Exception in thread "pool-1-thread-10" java.lang.OutOfMemoryError: Java heap space
- Exception in thread "pool-1-thread-49" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186587K->186534K(195584K), 0.3663284 secs]
- [Full GC (Allocation Failure) 186534K->186534K(195584K), 0.3445732 secs]
- Exception in thread "pool-1-thread-43" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186540K->186534K(195584K), 0.3350293 secs]
- [Full GC (Allocation Failure) 186534K->186534K(195584K), 0.3302049 secs]
- Exception in thread "pool-1-thread-46" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186540K->186534K(195584K), 0.3375518 secs]
- [Full GC (Allocation Failure) 186534K->186534K(195584K), 0.3233926 secs]
- Exception in thread "pool-1-thread-11" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186540K->186534K(195584K), 0.3457971 secs]
- [Full GC (Allocation Failure) 186534K->186534K(195584K), 0.3213070 secs]
- Exception in thread "pool-1-thread-7" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 187361K->186534K(195584K), 0.3381650 secs]
- [Full GC (Allocation Failure) 186534K->186534K(195584K), 0.3185285 secs]
- [Full GC (Ergonomics) 186541K->186534K(195584K), 0.3698434 secs]
- [Full GC (Allocation Failure) 186534K->186534K(195584K), 0.3116594 secs]
- Exception in thread "pool-1-thread-21" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186607K->186534K(195584K), 0.3356987 secs]
- [Full GC (Allocation Failure) 186534K->186534K(195584K), 0.3123781 secs]
- Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space
- Exception in thread "pool-1-thread-27" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186540K->186533K(195584K), 0.3382997 secs]
- [Full GC (Allocation Failure) 186533K->186533K(195584K), 0.3269648 secs]
- Exception in thread "pool-1-thread-34" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186853K->186533K(195584K), 0.3412933 secs]
- [Full GC (Allocation Failure) 186533K->186533K(195584K), 0.3179047 secs]
- [Full GC (Ergonomics) 186543K->186533K(195584K), 0.3286436 secs]
- [Full GC (Allocation Failure) 186533K->186533K(195584K), 0.3370087 secs]
- Exception in thread "pool-1-thread-5" java.lang.OutOfMemoryError: Java heap space
- Exception in thread "pool-1-thread-15" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 187382K->186532K(195584K), 0.3852196 secs]
- [Full GC (Ergonomics) 187071K->186532K(195584K), 0.3144036 secs]
- [Full GC (Allocation Failure) 186532K->186532K(195584K), 0.3237502 secs]
- Exception in thread "pool-1-thread-12" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186567K->186532K(195584K), 0.3716423 secs]
- [Full GC (Allocation Failure) 186532K->186532K(195584K), 0.3273201 secs]
- Exception in thread "pool-1-thread-2" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 186660K->186532K(195584K), 0.3708459 secs]
- [Full GC (Allocation Failure) 186532K->186532K(195584K), 0.3180280 secs]
- Exception in thread "pool-1-thread-23" java.lang.OutOfMemoryError: Java heap space
- [Full GC (Ergonomics) 187380K->186532K(195584K), 0.3686135 secs]
- [Full GC (Ergonomics) 187378K->186532K(195584K), 0.3624713 secs]
3、运维首先发现报警信息(CPU Memory)
4、top命令观察到问题:内存不断增长CPU占用率居高不下
再开一个窗口进行查看
- [root@localhost java]# top
- top - 23:34:29 up 1:07, 2 users, load average: 0.48, 0.54, 0.33
- Tasks: 126 total, 1 running, 125 sleeping, 0 stopped, 0 zombie
- %Cpu(s): 7.4 us, 0.5 sy, 0.0 ni, 92.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
- KiB Mem : 8008676 total, 6712688 free, 508676 used, 787312 buff/cache
- KiB Swap: 839676 total, 839676 free, 0 used. 7252628 avail Mem
-
- PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
- 1923 root 20 0 3783984 263912 12088 S 37.5 3.3 6:30.17 java
- 40 root 20 0 0 0 0 S 0.3 0.0 0:01.44 kworker/0:1
- 1 root 20 0 128144 6828 4160 S 0.0 0.1 0:01.75 systemd
- 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
- 4 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
- 6 root 20 0 0 0 0 S 0.0 0.0 0:00.03 ksoftirqd/0
- 7 root rt 0 0 0 0 S 0.0 0.0 0:00.03 migration/0
- 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
- 9 root 20 0 0 0 0 S 0.0 0.0 0:00.32 rcu_sched
- 10 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 lru-add-drain
- 11 root rt 0 0 0 0 S 0.0 0.0 0:00.04 watchdog/0
- 12 root rt 0 0 0 0 S 0.0 0.0 0:00.03 watchdog/1
- 13 root rt 0 0 0 0 S 0.0 0.0 0:00.00 migration/1
- 14 root 20 0 0 0 0 S 0.0 0.0 0:00.04 ksoftirqd/1
- 16 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
5、top -Hp PID号 :把进程中所有线程打印出来,观察进程中的线程,哪个线程CPU和内存占比高、此例子比较平均
- [root@localhost java]# top -Hp 1923
- top - 23:36:41 up 1:09, 2 users, load average: 0.18, 0.41, 0.31
- Threads: 65 total, 0 running, 65 sleeping, 0 stopped, 0 zombie
- %Cpu(s): 7.7 us, 0.3 sy, 0.0 ni, 92.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
- KiB Mem : 8008676 total, 6712484 free, 508776 used, 787416 buff/cache
- KiB Swap: 839676 total, 839676 free, 0 used. 7252476 avail Mem
-
- PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
- 1950 root 20 0 3783984 263912 12088 S 2.0 3.3 0:07.06 java
- 1982 root 20 0 3783984 263912 12088 S 1.7 3.3 0:07.23 java
- 1957 root 20 0 3783984 263912 12088 S 1.3 3.3 0:07.20 java
- 1965 root 20 0 3783984 263912 12088 S 1.3 3.3 0:07.09 java
- 1974 root 20 0 3783984 263912 12088 S 1.3 3.3 0:07.22 java
- 1977 root 20 0 3783984 263912 12088 S 1.3 3.3 0:07.20 java
- 1940 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.30 java
- 1941 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.30 java
- 1954 root 20 0 3783984 263912 12088 S 1.0 3.3 0:06.88 java
- 1955 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.19 java
- 1967 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.21 java
- 1969 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.45 java
- 1973 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.18 java
- 1979 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.03 java
- 1981 root 20 0 3783984 263912 12088 S 1.0 3.3 0:07.27 java
- 2067 root 20 0 3783984 263912 12088 S 1.0 3.3 0:02.72 jav
6、jstack PID : 把进程下的线程打印出来和状态
jstack定位线程状况,重点关注WAITING BLOCKED
eg. waiting on condition [0x00007f63236f5000]
阿里规范规定,【强制】创建线程或线程池时请指定有意义的线程名称,方便出错时回溯,怎么样自定义线程池里的线程名称?(自定义ThreadFactory)
- 正例:
- public class TimerTaskThread extends Thread{
-
- public TimerTaskThread(){
- super.setName("TimerTaskThread");
- //...
- }
- }
- [root@localhost ~]# jstack 1923
- 2023-11-28 23:51:52
- Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.202-b08 mixed mode):
-
- "Attach Listener" #78 daemon prio=9 os_prio=0 tid=0x00007f62f8001000 nid=0x89e waiting on condition [0x0000000000000000]
- java.lang.Thread.State: RUNNABLE
-
- "pool-1-thread-68" #77 prio=5 os_prio=0 tid=0x00007f62b4003800 nid=0x822 waiting on condition [0x00007f63236f5000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:897)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1222)
- at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1076)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-67" #76 prio=5 os_prio=0 tid=0x00007f62d8006800 nid=0x821 waiting on condition [0x00007f6322ceb000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:870)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1199)
- at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:209)
- at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:285)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1010)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1037)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ScheduledThreadPoolExecutor.reExecutePeriodic(ScheduledThreadPoolExecutor.java:346)
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:296)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-66" #75 prio=5 os_prio=0 tid=0x00007f62b0003800 nid=0x820 runnable [0x00007f63229e8000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:870)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1199)
- at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:209)
- at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:285)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1010)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1037)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ScheduledThreadPoolExecutor.reExecutePeriodic(ScheduledThreadPoolExecutor.java:346)
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:296)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-65" #74 prio=5 os_prio=0 tid=0x00007f62ac003800 nid=0x81f waiting on condition [0x00007f63237f6000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:870)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1199)
- at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:209)
- at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:285)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1010)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1037)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ScheduledThreadPoolExecutor.reExecutePeriodic(ScheduledThreadPoolExecutor.java:346)
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:296)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-64" #73 prio=5 os_prio=0 tid=0x00007f62d4003800 nid=0x81e waiting on condition [0x00007f63216d5000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:897)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1222)
- at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1076)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-63" #72 prio=5 os_prio=0 tid=0x00007f62d8009000 nid=0x81d waiting on condition [0x00007f6321ddc000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:897)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1222)
- at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1076)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-62" #71 prio=5 os_prio=0 tid=0x00007f62c4003800 nid=0x81c waiting on condition [0x00007f6322eed000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:870)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1199)
- at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:209)
- at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:285)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1010)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1037)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ScheduledThreadPoolExecutor.reExecutePeriodic(ScheduledThreadPoolExecutor.java:346)
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:296)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-61" #70 prio=5 os_prio=0 tid=0x00007f62e4002800 nid=0x81b waiting on condition [0x00007f63223e2000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:897)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1222)
- at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:335)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1076)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
-
- "pool-1-thread-60" #69 prio=5 os_prio=0 tid=0x00007f62ac002800 nid=0x81a waiting on condition [0x00007f63231f0000]
- java.lang.Thread.State: WAITING (parking)
- at sun.misc.Unsafe.park(Native Method)
- - parking to wait for <0x00000000faead268> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
- at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:870)
- at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1199)
- at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:209)
- at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:285)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.offer(ScheduledThreadPoolExecutor.java:1010)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:1037)
- at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.add(ScheduledThreadPoolExecutor.java:809)
- at java.util.concurrent.ScheduledThreadPoolExecutor.reExecutePeriodic(ScheduledThreadPoolExecutor.java:346)
- at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:296)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
- at java.lang.Thread.run(Thread.java:748)
7、jps定位具体java进程
- [root@localhost ~]# jps
- 1923 T15_FullGC_Problem01
- 2251 Jps
8、jinfo pid
- [root@localhost ~]# jinfo 1923
- Attaching to process ID 1923, please wait...
- Debugger attached successfully.
- Server compiler detected.
- JVM version is 25.202-b08
- Java System Properties:
-
- java.runtime.name = Java(TM) SE Runtime Environment
- java.vm.version = 25.202-b08
- sun.boot.library.path = /usr/java/jdk1.8.0_202/jre/lib/amd64
- java.vendor.url = http://java.oracle.com/
- java.vm.vendor = Oracle Corporation
- path.separator = :
- file.encoding.pkg = sun.io
- java.vm.name = Java HotSpot(TM) 64-Bit Server VM
- sun.os.patch.level = unknown
- sun.java.launcher = SUN_STANDARD
- user.country = US
- user.dir = /usr/java
- java.vm.specification.name = Java Virtual Machine Specification
- java.runtime.version = 1.8.0_202-b08
- java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
- os.arch = amd64
- java.endorsed.dirs = /usr/java/jdk1.8.0_202/jre/lib/endorsed
- java.io.tmpdir = /tmp
- line.separator =
-
- java.vm.specification.vendor = Oracle Corporation
- os.name = Linux
- sun.jnu.encoding = UTF-8
- java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
- java.specification.name = Java Platform API Specification
- java.class.version = 52.0
- sun.management.compiler = HotSpot 64-Bit Tiered Compilers
- os.version = 3.10.0-1160.71.1.el7.x86_64
- user.home = /root
- user.timezone =
- java.awt.printerjob = sun.print.PSPrinterJob
- file.encoding = UTF-8
- java.specification.version = 1.8
- user.name = root
- java.class.path = .:/usr/java/jdk1.8.0_202/lib/dt.jar:/usr/java/jdk1.8.0_202/lib/tools.jar
- java.vm.specification.version = 1.8
- sun.arch.data.model = 64
- sun.java.command = com.lwz.jvm.T15_FullGC_Problem01
- java.home = /usr/java/jdk1.8.0_202/jre
- user.language = en
- java.specification.vendor = Oracle Corporation
- awt.toolkit = sun.awt.X11.XToolkit
- java.vm.info = mixed mode
- java.version = 1.8.0_202
- java.ext.dirs = /usr/java/jdk1.8.0_202/jre/lib/ext:/usr/java/packages/lib/ext
- sun.boot.class.path = /usr/java/jdk1.8.0_202/jre/lib/resources.jar:/usr/java/jdk1.8.0_202/jre/lib/rt.jar:/usr/java/jdk1.8.0_202/jre/lib/sunrsasign.jar:/usr/java/jdk1.8.0_202/jre/lib/jsse.jar:/usr/java/jdk1.8.0_202/jre/lib/jce.jar:/usr/java/jdk1.8.0_202/jre/lib/charsets.jar:/usr/java/jdk1.8.0_202/jre/lib/jfr.jar:/usr/java/jdk1.8.0_202/jre/classes
- java.vendor = Oracle Corporation
- file.separator = /
- java.vendor.url.bug = http://bugreport.sun.com/bugreport/
- sun.io.unicode.encoding = UnicodeLittle
- sun.cpu.endian = little
- sun.cpu.isalist =
-
- VM Flags:
- Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=209715200 -XX:MaxHeapSize=209715200 -XX:MaxNewSize=69730304 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=69730304 -XX:OldSize=139984896 -XX:+PrintGC -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC
- Command line: -Xms200M -Xmx200M -XX:+PrintGC
-
- [root@localhost ~]#
9、jstat -gc pid :打印出各种gc信息,不直观,不常用
动态观察gc情况/阅读gc日志发现频繁gc/arthas观察/jconsole
jstat -gc pid 500:每隔500个毫秒打印gc的情况
- [root@localhost ~]# jstat -gc 1923
- S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
- 8192.0 8192.0 0.0 0.0 50688.0 50519.7 136704.0 136422.5 4864.0 3888.8 512.0 420.0 5 0.264 81 31.082 31.345
- [root@localhost ~]#
你是怎么定位OOM问题的?(面试)
1、命令行 / arthas
2、图形界面(jconsole、jvisualvm)用在什么地方?测试!
10、jmap -histo pid | head -20 :查找有多少对象产生
- [root@localhost ~]# jmap -histo 1923 | head -20
-
- num #instances #bytes class name
- ----------------------------------------------
- 1: 898656 64703232 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask
- 2: 898682 35947280 java.math.BigDecimal
- 3: 898656 28756992 com.lwz.jvm.T15_FullGC_Problem01$CardInfo
- 4: 898656 21567744 java.util.Date
- 5: 898656 21567744 java.util.concurrent.Executors$RunnableAdapter
- 6: 898656 14378496 com.lwz.jvm.T15_FullGC_Problem01$$Lambda$2/1044036744
- 7: 1 3594640 [Ljava.util.concurrent.RunnableScheduledFuture;
- 8: 15697 502304 java.util.concurrent.locks.AbstractQueuedSynchronizer$Node
- 9: 1612 126808 [C
- 10: 717 82216 java.lang.Class
- 11: 532 45904 [I
- 12: 1601 38424 java.lang.String
- 13: 792 35920 [Ljava.lang.Object;
- 14: 10 25232 [B
- 15: 57 21432 java.lang.Thread
- 16: 188 10528 java.lang.invoke.MemberName
- 17: 276 8832 java.util.concurrent.ConcurrentHashMap$Node
- [root@localhost ~]#
11、jmap -dump:format=b,file=xxx pid :导出堆转储文件(线上内存大,不推荐)
线上系统,内存特别大,jmap执行期间会对进程产生很大影响,甚至卡顿(电商不适合)
1、设定了参数 -XX:+HeapDumpOnOutOfMemoryError,OOM的时候会自动产生转储文件
2、很多服务器备份(高可用),停掉这台服务器对其他服务器不影响
3、在线定位 arthas
- [root@localhost ~]# jmap -dump:live,file=a.log 1923
- Dumping heap to /root/a.log ...
- Heap dump file created
12、java -Xms200M -Xmx200M -XX:+UseParallelGC -XX:+HeapDumpOnOutOfMemoryError com.lwz.jvm.T15_FullGC_Problem01
13、使用MAT/jhat/jvisualvm 导入dump文件 进行dump文件分析
- [root@localhost ~]# jhat -J-Xmx512M a.log
- Reading from a.log...
- Dump file created Thu Nov 30 00:02:26 CST 2023
- Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
- at com.sun.tools.hat.internal.parser.HprofReader.readInstance(HprofReade r.java:742)
- at com.sun.tools.hat.internal.parser.HprofReader.readHeapDump(HprofReade r.java:491)
- at com.sun.tools.hat.internal.parser.HprofReader.read(HprofReader.java:2 38)
- at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:92)
- at com.sun.tools.hat.Main.main(Main.java:159)
- [root@localhost ~]#
java命令--jhat命令
jhat命令:主要是用来分析java堆的命令,可以将堆中的对象以html的形式显示出来,包括对象的数量,大小等等,并支持对象查询语言。
使用jmap等方法生成java的堆文件后,使用其进行分析。
第一步:导出堆
jmap -dump:live,file=a1.log pid [root@localhost java]# jmap -dump:live,file=a2.log 3362 Dumping heap to /usr/java/a2.log ... Heap dump file created除了使用jmap命令,还可以通过以下方式:
1、使用 jconsole 选项通过 HotSpotDiagnosticMXBean 从运行时获得堆转储(生成dump文件)
2、虚拟机启动时如果指定了 -XX:+HeapDumpOnOutOfMemoryError 选项, 则在抛出 OutOfMemoryError 时, 会自动执行堆转储。
3、使用 hprof 命令--(arthas heapdump文件)第二步:分析堆文件
jhat -J-Xmx512M a1.log [root@localhost java]# jhat -J-Xmx512M a1.log Reading from a1.log... Dump file created Sun Dec 03 21:27:09 CST 2023 Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Hashtable.rehash(Hashtable.java:402) at java.util.Hashtable.addEntry(Hashtable.java:426) at java.util.Hashtable.put(Hashtable.java:477) at com.sun.tools.hat.internal.model.Snapshot.addHeapObject(Snapshot.java:166) at com.sun.tools.hat.internal.parser.HprofReader.readInstance(HprofReader.java:744) at com.sun.tools.hat.internal.parser.HprofReader.readHeapDump(HprofReader.java:491) at com.sun.tools.hat.internal.parser.HprofReader.read(HprofReader.java:238) at com.sun.tools.hat.internal.parser.Reader.readFile(Reader.java:92) at com.sun.tools.hat.Main.main(Main.java:159) [root@localhost java]# ====>重新导出一个小文件,执行下面命令 [root@localhost java]# jhat -J-Xmx512M a2.log Reading from a2.log... Dump file created Sun Dec 03 21:49:05 CST 2023 Snapshot read, resolving... Resolving 329332 objects... Chasing references, expect 65 dots................................................................. Eliminating duplicate references................................................................. Snapshot resolved. Started HTTP server on port 7000 Server is ready. ==>解析Java堆转储文件,并启动一个 web server第三步:查看html
http://ip:7000/
对于jhat启动后显示的html页面中功能:
(1)显示出堆中所包含的所有的类(2)显示平台包括的所有类的实例数量
(3)堆实例的分布表
(4)执行对象查询语句
jhat中的OQL(对象查询语言) 如果需要根据某些条件来过滤或查询堆的对象,这是可能的,可以在jhat的html页面中执行OQL,来查询符合条件的对象 基本语法: select <javascript expression to select> [from [instanceof] <class name> <identifier>] [where <javascript boolean expression to filter>] 解释: (1)class name是java类的完全限定名,如:java.lang.String, java.util.ArrayList, [C是char数组, [Ljava.io.File是java.io.File[] (2)类的完全限定名不足以唯一的辨识一个类,因为不同的ClassLoader载入的相同的类,它们在jvm中是不同类型的 (3)instanceof表示也查询某一个类的子类,如果不明确instanceof,则只精确查询class name指定的类 (4)from和where子句都是可选的 (5)java域表示:obj.field_name;java数组表示:array[index] 举例: (1)查询长度大于100的字符串 select s from java.lang.String s where s.count > 100 (2)查询长度大于256的数组 select a from [I a where a.length > 256 (3)显示匹配某一正则表达式的字符串 select a.value.toString() from java.lang.String s where /java/(s.value.toString()) (4)显示所有文件对象的文件路径 select file.path.value.toString() from java.io.File file (5)显示所有ClassLoader的类名 select classof(cl).name from instanceof java.lang.ClassLoader cl (6)通过引用查询对象 select o from instanceof 0xd404d404 o built-in对象 -- heap (1)heap.findClass(class name) -- 找到类 select heap.findClass("java.lang.String").superclass (2)heap.findObject(object id) -- 找到对象 select heap.findObject("0xd404d404") (3)heap.classes -- 所有类的枚举 select heap.classes (4)heap.objects -- 所有对象的枚举 select heap.objects("java.lang.String") (5)heap.finalizables -- 等待垃圾收集的java对象的枚举 (6)heap.livepaths -- 某一对象存活路径 select heaplivepaths(s) from java.lang.String s (7)heap.roots -- 堆根集的枚举 辨识对象的函数 (1)classof(class name) -- 返回java对象的类对象 select classof(cl).name from instanceof java.lang.ClassLoader cl (2)identical(object1,object2) -- 返回是否两个对象是同一个实例 select identical(heap.findClass("java.lang.String").name, heap.findClass("java.lang.String").name) (3)objectid(object) -- 返回对象的id select objectid(s) from java.lang.String s (4)reachables -- 返回可从对象可到达的对象 select reachables(p) from java.util.Properties p -- 查询从Properties对象可到达的对象 select reachables(u, "java.net.URL.handler") from java.net.URL u -- 查询从URL对象可到达的对象,但不包括从URL.handler可到达的对象 (5)referrers(object) -- 返回引用某一对象的对象 select referrers(s) from java.lang.String s where s.count > 100 (6)referees(object) -- 返回某一对象引用的对象 select referees(s) from java.lang.String s where s.count > 100 (7)refers(object1,object2) -- 返回是否第一个对象引用第二个对象 select refers(heap.findObject("0xd4d4d4d4"),heap.findObject("0xe4e4e4e4")) (8)root(object) -- 返回是否对象是根集的成员 select root(heap.findObject("0xd4d4d4d4")) (9)sizeof(object) -- 返回对象的大小 select sizeof(o) from [I o (10)toHtml(object) -- 返回对象的html格式 select "" + toHtml(o) + "" from java.lang.Object o (11)选择多值 select {name:t.name?t.name.toString():"null",thread:t} from instanceof java.lang.Thread t 数组、迭代器等函数 (1)concat(enumeration1,enumeration2) -- 将数组或枚举进行连接 select concat(referrers(p),referrers(p)) from java.util.Properties p (2)contains(array, expression) -- 数组中元素是否满足某表达式 select p from java.util.Properties where contains(referres(p), "classof(it).name == 'java.lang.Class'") 返回由java.lang.Class引用的java.util.Properties对象 built-in变量 it -- 当前的迭代元素 index -- 当前迭代元素的索引 array -- 被迭代的数组 (3)count(array, expression) -- 满足某一条件的元素的数量 select count(heap.classes(), "/java.io./(it.name)") (4)filter(array, expression) -- 过滤出满足某一条件的元素 select filter(heap.classes(), "/java.io./(it.name)") (5)length(array) -- 返回数组长度 select length(heap.classes()) (6)map(array,expression) -- 根据表达式对数组中的元素进行转换映射 select map(heap.classes(),"index + '-->' + toHtml(it)") (7)max(array,expression) -- 最大值, min(array,expression) select max(heap.objects("java.lang.String"),"lhs.count>rhs.count") built-in变量 lhs -- 左边元素 rhs -- 右边元素 (8)sort(array,expression) -- 排序 select sort(heap.objects('[C'),'sizeof(lhs)-sizeof(rhs)') (9)sum(array,expression) -- 求和 select sum(heap.objects('[C'),'sizeof(it)') (10)toArray(array) -- 返回数组 (11)unique(array) -- 唯一化数组原文链接:https://www.cnblogs.com/baihuitestsoftware/articles/6406271.html
14、找到代码的问题
1、程序启动加入参数:起jmx协议
- java -Djava.rmi.server.hostname=192.168.18.70
- -Dcom.sun.management.jmxremote
- -Dcom.sun.management.jmxremote.port=11111
- -Dcom.sun.management.jmxremote.authenticate=false
- -Dcom.sun.management.jmxremote.ssl=false
- -Xms200M -Xmx200M -XX:+PrintGC com.lwz.jvm.T15_FullGC_Problem01
注意:执行时,把上面命令整成一行执行
2、关闭防火墙
- 关闭了linux的防火墙,才能在外面访问到对应的服务
- service firewalld status ;查看防火墙状态
- service firewalld stop:关闭防火墙
3、windows上打开jconsole远程连接 192.168.18.70:11111


点击不安全的连接


文件--添加JMX连接

监视

内存中的对象占用内存比较大,问题很可能出现在这里


导入a2.log

可以分析dump文件
再小的努力,乘以365都很明显!
一个程序员最重要的能力是:写出高质量的代码!!
有道无术,术尚可求也,有术无道,止于术。
无论你是年轻还是年长,所有程序员都需要记住:时刻努力学习新技术,否则就会被时代抛弃!