I recently discovered logs filling up with log messages for classes being unloaded during garbage collection. After a little research, I found that the TraceClassUnloading switch gets turned on by the Xloggc switch. After a little testing, I found that this can be resolved by adding the argument -XX:-TraceClassUnloading after the -Xloggc argument.
This problem occurs with the Sun Java 6 JDK but appears resolved in the Java 7 JDK. Other JDKs may use different flags and may not have the same behavior.
I have included my test class and script if you want to run your own tests. The final option resolves the problem.
Test Class
To test the settings I created a minimal Java program that sleeps 15 seconds. This allows time to examine the final Java flags. Any program which runs for several seconds could be used.
public class Sleep15 {
/** Sleeps 15 seconds and exits.
*/
public static void main(String[] args) {
try {
Thread. sleep(15 * 1000);
} catch (InterruptedException e) {
// e.printStackTrace();
}
}
}
Test Script
The following test script checks the above program with three sets of arguments. The JAVA_HOME
variable is used to determine the JDK
to test.
#!/bin/bash echo "Java_home: ${JAVA_HOME}" for OPTS in ' ' '-XX:-TraceClassUnloading -Xloggc:gc.log' \ '-Xloggc:gc.log -XX:-TraceClassUnloading'; do echo -e "\nOPTS: ${OPTS}" ${JAVA_HOME}/bin/java ${OPTS} Sleep15 & sleep 5 ${JAVA_HOME}/bin/jinfo -flag TraceClassUnloading $! kill $! done