How to do force full garbage collection when heap usage goes beyond a certain threshold

Thomas Schatzl thomas.schatzl at oracle.com
Mon Feb 24 08:56:46 UTC 2020


Hi,

On 24.02.20 08:45, mohd shaban wrote:
> Hi Team,
> 
> Is there a way to force GC when heap usage goes beyond a certain threshold?.
> I am using G1GC Algorithm.
> 
> Thanks,
> Mohd Shaban
> 

   G1 fully supports the MemoryMXBean API [0] to monitor memory usage 
either via polling or notifications.

You can issue a System.gc() in response to this information. It forces 
some kind of GC.

Hth,
   Thomas

[0] 
https://docs.oracle.com/javase/10/docs/api/java/lang/management/MemoryMXBean.html


More information about the hotspot-gc-use mailing list