Getting GC settings for running JVM [duplicate]

2019-09-05 07:25发布

This question already has an answer here:

Is there a way to get the GC settings for a running JVM?

I'm trying to see what GC algorithm is running SerialGC, ParallelGC, ParallelOldGC, ConcurrentMarkSweepGC, ect.

2条回答
萌系小妹纸
2楼-- · 2019-09-05 07:50

You can use jconsole and access some JMX beans of your JVM in its GUI. There you can see details of GC for Tenured or Young parts of JVM Memory. It's just in your jdk/bin folder (HotSpot)

Here is some useful resources:

Using JConsole

查看更多
看我几分像从前
3楼-- · 2019-09-05 07:52

JVM has a nice MBean for that:

for(GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
   System.out.println(gc.getObjectName());
}

You should see MBeans names like "PS Scavenge" or "PS Mark Sweep". Use the following reference to match names with algorithms:

Copy (Young) - Copying collector

ParNew (Young) - Parallel young generation collector

PS Scavenge (Young) - Parallel object scavenger

MarkSweepCompact (Old) - Mark and sweep compactor

ConcurrentMarkSweep (Old) - Concurrent mark and sweep compactor

PS MarkSweep (Old) - Parallel mark and sweep collector

The same information can also be collected with any tool capanle of viewing MBeans: JConsole, JVisualVM, Jprofiler, etc.

查看更多
登录 后发表回答