Other Garbage Collector Settings

To specify the attributes for the Java virtual machine, use the Administration Console and set the property under config-name → JVM settings (JVM options).

Setting the Maximum Permanent Generation

For applications that do not dynamically generate and load classes, the size of the permanent generation does not affect GC performance. For applications that dynamically generate and load classes (for example, JSP applications), the size of the permanent generation does affect GC performance, since filling the permanent generation can trigger a Full GC. Tune the maximum permanent generation with the -XX:MaxPermSize option.

Disabling Explicit Garbage Collection

Although applications can explicitly invoke GC with the System.gc() method, doing so is a bad idea since this forces major collections, and inhibits scalability on large systems. It is best to disable explicit GC by using the flag -XX:+DisableExplicitGC.


Note - On Windows systems, setting the -XX:+DisableExplicitGC option might prevent the renaming or removal of open application files. As a result, deployment, redeployment, or other operations that attempt to rename or delete files might fail.

Application files can remain open because the files have been used by class loaders to find classes or resources, or have been opened explicitly by GlassFish Server or application code but never explicitly closed. On Windows systems, open files cannot be renamed or deleted. To overcome this limitation, GlassFish Server uses the System.gc() method to garbage collect the Java object that corresponds to an open file. When the Java object that corresponds to an open file is garbage collected, the object's finalize method closes the open channel to the file. GlassFish Server can then delete or rename the file.


Setting the Frequency of Full Garbage Collection

GlassFish Server uses RMI in the Administration module for monitoring. Garbage cannot be collected in RMI-based distributed applications without occasional local collections, so RMI forces a periodic full collection. Control the frequency of these collections with the property -sun.rmi.dgc.client.gcInterval. For example, - java -Dsun.rmi.dgc.client.gcInterval=3600000 specifies explicit collection once per hour instead of the default rate of once per minute.