本文介绍了在 Java 中滚动垃圾收集器日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Sun JVM 中滚动垃圾收集器日志?

Is it possible to do a rolling of garbage collector logs in Sun JVM?

目前我使用以下方法生成日志:

Currently I generate logs using:

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -verbose:gc -Xloggc:gc.log 

但我必须使用先进先出队列和旋转日志手动轮换它们,以便为每一天创建一个新日志.我希望有更好的解决方案.

But I have to manually rotate them using fifo queues and rotatelogs to create a new log for each day. I hope that there is a better solution for this.

也许有一种方法可以从 Java 内部访问此日志条目,以便我可以将它们重定向到 log4j?

Maybe there is a way to access this log entries from inside java so I could redirect them to log4j?

使用fifo队列的解决方案不够好,因为如果从这个队列读取的进程(例如rotatelogs)读取速度变慢,它将减慢整个jvm的速度(显然Sun/Oracle是同步进行gc日志记录的)

the solution with fifo queue is not good enough because if the process that reads from this queue (e.g. rotatelogs) reads to slow it will slow down the entire jvm (apparently Sun/Oracle does gc logging synchronously)

推荐答案

HotSpot JVM 中添加了对 GC 日志轮换的内置支持.它在 RFE 6941923 中有所描述,可在:

Built-in support for GC log rotation has been added to the HotSpot JVM.It is described in the RFE 6941923 and is available in:

有三个新的 JVM 标志可用于启用和配置它:

There are three new JVM flags that can be used to enable and configure it:

  • -XX:+UseGCLogFileRotation
    必须与-Xloggc:;
  • 一起使用
  • -XX:NumberOfGCLogFiles=
    必须>=1,默认为1;
  • -XX:GCLogFileSize=M(或 K)
    默认设置为 512K.

这篇关于在 Java 中滚动垃圾收集器日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 06:37