Garbage collector log (loggc) file rotation with logrotate does not work properly
We had the same problem at our place running Jboss7 and Java6, we were getting NULLs in the GC file and they just kept growing.
Solution was to just log GC to stdout and then append stdout to a file:
Simple example:
java -verbose:gc >> console.log
Apparently using append (>>) gets rid of the Java "pointer" to a position in the file. With the added bonus of not having the GC logs reset per server restart so we can have some stats over time.
At least the IBM PMAT tool has no problem parsing the sysout with GC output.
The simplest solution is sometimes the best :)
Though I wish Java would support rotating of GC logs, as I see someone's been discussing before:
http://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2011-April/002061.html
JVM gc log not rotating
It seems you've already figured that out yourself. GCLogFileSize
has the minimum value of 8KB in JDK, even if you try to set less. Here is the relevant fragment from HotSpot sources:
if (UseGCLogFileRotation && (GCLogFileSize != 0) && (GCLogFileSize < 8*K)) {
FLAG_SET_CMDLINE(uintx, GCLogFileSize, 8*K);
jio_fprintf(defaultStream::output_stream(),
"GCLogFileSize changed to minimum 8K\n");
}
Rolling garbage collector logs in java
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:
- Java 6 Update 34
- Java 7 Update 2 (but there is no reference to it in these release notes)
There are three new JVM flags that can be used to enable and configure it:
-XX:+UseGCLogFileRotation
must be used with-Xloggc:<filename>
;-XX:NumberOfGCLogFiles=<number of files>
must be >=1, default is one;-XX:GCLogFileSize=<number>M (or K)
default will be set to 512K.
GC log rotation data lose on application restart
You can also use java own timestamps for that:
java -Xloggc:gc-%t.log ...(rest of your line)...
%t
will be replaced with a timestamp by java (see https://bugs.openjdk.java.net/browse/JDK-6950794 for information and other formats supported by -Xloggc
Related Topics
How to Create a Bks (Bouncycastle) Format Java Keystore That Contains a Client Certificate Chain
Javafx Freeze on Desktop.Open(File), Desktop.Browse(Uri)
Does Python Have an Equivalent to Java Class.Forname()
Upload Files from Java Client to a Http Server
Recommended Jsf 2.0 Crud Frameworks
How to Do a Junit Assert on a Message in a Logger
Different Dependencies for Different Build Profiles
Java: Run a Function After a Specific Number of Seconds
Using the Keyword "This" in Java
Error: Unable to Run Mksdcard Sdk Tool
Opening a Shell and Interacting with Its I/O in Java
JPA Cascadetype.All Does Not Delete Orphans
Java 1.6 - Determine Symbolic Links
Java 8: Lambda-Streams, Filter by Method with Exception