1

Hi as per the documentation here https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/concurrent.html#mostly_concurrent the hotspot JVM has 2 concurrent collectors - the CMS and G1. So during garbage collection are both of these used parallelly or is just one selected?

Trooper
  • 145
  • 3
  • 15

1 Answers1

4

No, they won't run at the same time.

In fact, CMS and G1 are alternative low-pause collectors.

You can configure the JVM to use either CMS, or G1, or one of the other collectors; e.g. the "stop-the-world" throughput collector, Shenandoah (Java 12) (https://wiki.openjdk.java.net/display/shenandoah/Main), Z GC (Java 12) and so on.

In fact, CMS is deprecated as of Java 9, and some of the CMS-related GC flag combinations have already been dropped.


A bit of terminology to help you understand.

  • Parallel GC is when the GC uses multiple threads when it is running.
  • Concurrent GC is when the GC runs concurrently with (i.e. at the same time as) application code.
  • Tandem GC ... there is no such thing.

Some collectors are both concurrent and parallel.

AFAIK, Java collectors are 100% concurrent. All of the so-called concurrent collectors have short periods of time when all application threads must be suspended. (Depending on the specific GC, the tuning options and the workload, these pauses could be 10s or 100s of milliseconds. This is why the GC's are described as "low-pause" not "no-pause".)

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thank you. And I assume when we do not pass any GC parameter explicitly, the default GC will be used as answered here - https://stackoverflow.com/a/43486993/3393469 Please do correct me if am wrong. – Trooper Mar 30 '19 at 09:19
  • Yes you can assume that. (That's what default means!) Note, I haven't checked the accuracy of that answer, and he dosn't say how he concluded that / what his sources are. But there are jvm options to get the jvm to print out all active settings on startup, so he could have used that. – Stephen C Mar 30 '19 at 09:22