启动jvm时加上一些参数即可
常用参数:
java \
-Xmx4G \
-XX:+UseG1GC \
-XX:MaxGCPauseMillis=200 \
-XX:ConcGCThreads=2 \
-XX:+PrintGC \
-XX:+PrintHeapAtGC \
-XX:+PrintGCDetails \
-XX:+PrintGCTimeStamps \
-XX:+HeapDumpOnOutOfMemoryError \
-XX:+PrintGCApplicationStoppedTime \
-Xloggc:gc.log \
-XX:OnError="echo error" \
-XX:OnOutOfMemoryError="echo OnOutOfMemoryError" \
日志输出:
2016-07-28T10:44:39.345-0800: 6.282: [GC [PSYoungGen: 34320K->496K(38912K)] 34328K->504K(125952K), 0.0021030 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
* 0.0021030 secs (gc耗时)
* PSYoungGen (young gc)