The option “-XX:+ExplicitGCInvokesConcurrent” enables invoking of concurrent Garbage Collector (GC) by using the “System.gc()” request.
Starting from JDK 6.
java -XX:+ExplicitGCInvokesConcurrent MainClass
Before talking about the flag, we need to introduce Garbage Collector (GC):
Garbage Collector is a way of the JVM to clean the memory and makes the java memory more efficient. It tracks (Mark step) and removes (sweep step) every unused object available in the JVM heap space. An object is considered unused when it’s referenced by null, assigned to another reference or by anonymous object …. There are 5 type of GC implementations:
- Serial Garbage Collector
- Parallel Garbage Collector
- CMS Garbage Collector
- G1 Garbage Collector
- Z Garbage Collector
CMS Garbage Collector, as mentioned above, is one of the implementations of GC, which uses multiple thread for garbage collection. It’s created for applications that favor shorter garbage collection pauses and that can afford to share processor resources with the garbage collector while the application is running. It achieves long pauses by two ways:
- By using free lists to manage reclaimed space instead of compacting the Old Generation.
- By doing mainly the job in Mark (marking a reference) and Sweep (removing the marked reference) process simultaneously with the application. Which means that the GC is not stopping or freezing the application’s threads to do its job. But it does take part of using the CPU time with the application. By default, GC algorithm can use number of threads up to ¼ of the number of physical cores of your machine.
The flag “-XX:+ExplicitGCInvokesConcurrent” instructs the JVM to run a Concurrent Mark Sweep (CMS) Garbage Collector (GC) instead of a full GC whenever system GC is requested.
This option is disabled by default and can be enabled only together with the “-XX:+UseConcMarkSweepGC” and “-XX:+UseG1GC” options.
- Garbage collection (computer science)
- Concurrent Mark Sweep
- Useful JVM Flags – Part 7 (CMS Collector)
- Java Garbage Collection Basics
Edit your Comment