System.gc()

When 'System.gc()' or 'Runtime.getRuntime().gc()' API calls are invoked from your application, stop-the-world Full GC events will be triggered. You can fix this problem through following solutions:


a. -XX:+DisableExplicitGC

You can forcefully disable System.gc() calls by passing the JVM argument -'XX:+DisableExplicitGC' when you launch the application. This option will silence all the 'System.gc()' calls that are invoked from your application stack.


b. -XX:+ExplicitGCInvokesConcurrent

You can pass '-XX:+ExplicitGCInvokesConcurrent' JVM argument. When this argument is passed, GC collections run concurrently along with application threads to reduce the lengthy pause time.


c. Search & Replace

This might be a traditional method :-), but it works. Search in your application code base for 'System.gc()' and 'Runtime.getRuntime().gc()'. If you see a match, then remove it. This solution will work if 'System.gc()' is invoked from your application source code. If 'System.gc()' is going to be invoked from your 3rd party libraries, frameworks, or through external sources then this solution will not work. In such circumstance, you can consider using the option outlined in #b and #c.


d. RMI

If your application is using RMI, you can control the frequency in which 'System.gc()' calls are made. This frequency can be configured using the following JVM arguments when you launch the application:

-Dsun.rmi.dgc.server.gcInterval=n
-Dsun.rmi.dgc.client.gcInterval=n

The default value for these properties in

JDK 1.4.2 and 5.0 is 60000 milliseconds (i.e. 60 seconds)

JDK 6 and later release is 3600000 milliseconds (i.e. 60 minutes)

You might want to set these properties to a very high value so that it can minimize the impact.

For more details about 'System.gc()' calls, and it's GC impact you can refer to this article.