3

JVM - GC日志参数

 2 years ago
source link: https://chanjarster.github.io/post/jvm/gc-log-options/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

介绍怎么开启GC日志采集。

Java <= 8

-XX:+PrintGC
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
-Xloggc:/path/to/gc.log
-XX:+UseGCLogFileRotation
-XX:GCLogFileSize=1M
-XX:NumberOfGCLogFiles=5

前4个参数文档在Java 8文档 ,后两个参数的文档只能在Java 7文档 看到,不过Java 8也能用。

如果你不想要日志滚动,可以这样:

-XX:+PrintGC
-XX:+PrintGCTimeStamps
-XX:+PrintGCDetails
-Xloggc:/path/to/gc-%t.log

形成的文件会是YYYY-MM-DD_HH-MM-SS(程序启动的时间)这个形式(见这篇Blog )。

Java >= 9

Java 9开始,使用Xlog(文档) 统一了所有日志的输出,所以参数要变化:

-Xlog:gc*:file=/path/to/gc.log:time,level,tags:filecount=5,filesize=5M

如果你不想要日志滚动,可以这样:

-Xlog:gc*:file=/path/to/gc-%t.log:time,level,tags:filecount=0

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK