public enum GcControls extends Enum<GcControls>
These utilities are used to request and wait for garbage collection cycles. Please note that relying on explicit garbage collection is inherently unreliable, and these methods should be used with caution.
| Modifier and Type | Method and Description |
|---|---|
static long |
getGcCount()
Retrieves the total count of garbage collection (GC) cycles that have occurred.
|
static void |
requestGcCycle()
Requests a garbage collection (GC) cycle to be performed.
|
static GcControls |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static GcControls[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
static void |
waitForGcCycle()
Requests a garbage collection (GC) cycle and blocks until it occurs or a timeout is reached.
|
public static GcControls[] values()
for (GcControls c : GcControls.values()) System.out.println(c);
public static GcControls valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant with the specified nameNullPointerException - if the argument is nullpublic static void requestGcCycle()
This method is a hint to the JVM, and there's no guarantee the GC will actually be performed.
public static void waitForGcCycle()
This method waits for up to one second for a GC cycle to occur. If the GC does not occur
within this time, an IllegalStateException is thrown.
IllegalStateException - if the GC doesn't occur within one secondpublic static long getGcCount()
This method returns the sum of collection counts for all types of garbage collectors within the JVM.
Copyright © 2023. All rights reserved.