Class GcTimeMonitor

All Implemented Interfaces:
Runnable

public class GcTimeMonitor extends SubjectInheritingThread
This class monitors the percentage of time the JVM is paused in GC within the specified observation window, say 1 minute. The user can provide a hook which will be called whenever this percentage exceeds the specified threshold.
  • Constructor Details

    • GcTimeMonitor

      public GcTimeMonitor(long observationWindowMs, long sleepIntervalMs, int maxGcTimePercentage, GcTimeMonitor.GcTimeAlertHandler alertHandler)
      Create an instance of GCTimeMonitor. Once it's started, it will stay alive and monitor GC time percentage until shutdown() is called. If you don't put a limit on the number of GCTimeMonitor instances that you create, and alertHandler != null, you should necessarily call shutdown() once the given instance is not needed. Otherwise, you may create a memory leak, because each running GCTimeMonitor will keep its alertHandler object in memory, which in turn may reference and keep in memory many more other objects.
      Parameters:
      observationWindowMs - the interval over which the percentage of GC time should be calculated. A practical value would be somewhere between 30 sec and several minutes.
      sleepIntervalMs - how frequently this thread should wake up to check GC timings. This is also a frequency with which alertHandler will be invoked if GC time percentage exceeds the specified limit. A practical value would likely be 500..1000 ms.
      maxGcTimePercentage - A GC time percentage limit (0..100) within observationWindowMs. Once this is exceeded, alertHandler will be invoked every sleepIntervalMs milliseconds until GC time percentage falls below this limit.
      alertHandler - a single method in this interface is invoked when GC time percentage exceeds the specified limit.
  • Method Details