Full GC (Metadata GC Threshold)

问题描述

启动tomcat,查看gc日志,发现启动之时连续出现了3次Full GC,具体日志如下:

13.548: [GC (Metadata GC Threshold) [PSYoungGen: 236186K->54959K(571392K)] 357547K->187204K(746496K), 0.1061141 secs] [Times: user=0.20 sys=0.01, real=0.10 secs]
13.655: [Full GC (Metadata GC Threshold) [PSYoungGen: 54959K->0K(571392K)] [ParOldGen: 132244K->79787K(188416K)] 187204K->79787K(759808K), [Metaspace: 20674K->20674K(1069056K)], 0.2597448 secs] [Times: user=0.47 sys=0.01, real=0.26 secs]
17.015: [GC (Metadata GC Threshold) [PSYoungGen: 241835K->25116K(495104K)] 321623K->104911K(683520K), 0.0375484 secs] [Times: user=0.07 sys=0.00, real=0.04 secs]
17.053: [Full GC (Metadata GC Threshold) [PSYoungGen: 25116K->0K(495104K)] [ParOldGen: 79795K->98674K(226816K)] 104911K->98674K(721920K), [Metaspace: 34389K->34389K(1081344K)], 0.1554940 secs] [Times: user=0.23 sys=0.00, real=0.16 secs]
19.635: [GC (Allocation Failure) [PSYoungGen: 469504K->48895K(570368K)] 568178K->147577K(797184K), 0.0517696 secs] [Times: user=0.10 sys=0.00, real=0.06 secs]
23.982: [GC (Metadata GC Threshold) [PSYoungGen: 430071K->32104K(567296K)] 528753K->174873K(794112K), 0.1259098 secs] [Times: user=0.23 sys=0.00, real=0.13 secs]
24.108: [Full GC (Metadata GC Threshold) [PSYoungGen: 32104K->0K(567296K)] [ParOldGen: 142769K->154136K(315904K)] 174873K->154136K(883200K), [Metaspace: 57759K->57759K(1101824K)], 0.5632292 secs] [Times: user=1.02 sys=0.02, real=0.56 secs]

原因描述

使用java -XX:+PrintFlagsInitial命令查看虚拟机的默认参数:


可以看到MetaspaceSize的默认值是21810376,而频繁发生Full GC正是由于MetaspaceSize的默认值太小所致。

解决方案

设置JVM启动参数:-XX:MetaspaceSize=128m

参考资料

  • fullgc问题解决:Full GC (Metadata GC Threshold)
  • Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide

你可能感兴趣的:(Full GC (Metadata GC Threshold))