Package org.apache.solr.util
Class ThreadCpuTimer
java.lang.Object
org.apache.solr.util.ThreadCpuTimer
Allows tracking information about the current thread using the JVM's built-in management bean
ThreadMXBean. Methods on this class are safe for use on any thread,
but will return different values for different threads by design.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbeginContext(String context) static booleanreadMSandReset(String context) readNSAndReset(String context) Get the number of nanoseconds since the last time this thread took a reading for the supplied context.static voidreset()Cleanup method.static voidDiscard any accumulated time for a given context since the last invocation.toString()
-
Field Details
-
CPU_TIME
- See Also:
-
LOCAL_CPU_TIME
- See Also:
-
ENABLE_CPU_TIME
- See Also:
-
-
Method Details
-
beginContext
-
isSupported
public static boolean isSupported() -
readNSAndReset
Get the number of nanoseconds since the last time this thread took a reading for the supplied context.- Parameters:
context- An arbitrary name that code can supply to avoid clashing with other usages.- Returns:
- An optional long which may be empty if java.lang.management.ManagementFactory#getThreadMXBean() is unsupported or otherwise unavailable.
-
reset
Discard any accumulated time for a given context since the last invocation.- Parameters:
context- the context to reset
-
readMSandReset
-
reset
public static void reset()Cleanup method. This should be called at the very end of a request thread when it's absolutely sure no code will attempt a new reading. -
toString
-