Reputation: 7423
I'm looking for a technique to find out the Garbage Collection (GC) strategy (collector) the Java VM is using at a given point of time. (Later on, I'd like it to correctly reflect the strategy that I choose, say XX:+UseConcMarkSweepGC
.)
verbose:gc
(in its basic form) does not help as it just shows me what all it did with each generation. Is there any other flag I can set to make it spit out the GC strategy being utilized?
JDK version is 1.6_21
Upvotes: 3
Views: 6887
Reputation: 8672
If you want to get this information at runtime in the application that is running on the JVM, then you can use the GarbageCollectorMXBean:
List<GarbageCollectorMXBean> gcs =
ManagementFactory.getGarbageCollectorMXBeans();
for (GarbageCollectorMXBean gc : gcs) {
System.out.println(gc.getName());
}
Upvotes: 4
Reputation: 51431
Mmmm.. you can certainly find out what strategy is being used by a certain JVM with jconsole (VM Summary) page. Not sure about influencing it, or changing it.
EDIT:
To assist you with programmatically checking and changing JVM flags of a running VM you can use the jinfo.exe
utility in the JDK. For example to check if the ParallelGC flag is set you can run: jinfo.exe -flag UseParallelGC <PID>
.
Upvotes: 8
Reputation: 1392
you can try jinfo utility provided with JDK. Provide the JVM process PID to this utility and it will display you all the generic argument passed to this JVM process. Following is the URL for the same :
http://download.oracle.com/javase/6/docs/technotes/tools/share/jinfo.html
Hope it helps.
Upvotes: 1