Package org.apache.hadoop.util
Class GcTimeMonitor
java.lang.Object
java.lang.Thread
org.apache.hadoop.util.concurrent.SubjectInheritingThread
org.apache.hadoop.util.GcTimeMonitor
- All Implemented Interfaces:
Runnable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classEncapsulates data about GC pauses measured at the specific timestamp.static interfaceThe user can provide an instance of a class implementing this interface when initializing a GcTimeMonitor to receive alerts when GC time percentage exceeds the specified threshold.Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionGcTimeMonitor(long observationWindowMs, long sleepIntervalMs, int maxGcTimePercentage, GcTimeMonitor.GcTimeAlertHandler alertHandler) Create an instance of GCTimeMonitor. -
Method Summary
Modifier and TypeMethodDescriptionReturns a copy of the most recent data measured by this monitor.voidshutdown()voidwork()This is the equivalent ofThread.run().Methods inherited from class org.apache.hadoop.util.concurrent.SubjectInheritingThread
run, startMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, suspend, toString, yield
-
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
-
work
public void work()Description copied from class:SubjectInheritingThreadThis is the equivalent ofThread.run(). Override this instead ofSubjectInheritingThread.run()Subject will be propagated like in pre-Java 22 Thread.- Overrides:
workin classSubjectInheritingThread
-
shutdown
public void shutdown() -
getLatestGcData
Returns a copy of the most recent data measured by this monitor.- Returns:
- a copy of the most recent data measured by this monitor
-