Package org.apache.solr.util
Class ThreadCpuTimer
- java.lang.Object
-
- org.apache.solr.util.ThreadCpuTimer
-
public class ThreadCpuTimer extends Object
Allows tracking information about the current thread using the JVM's built-in management beanThreadMXBean
. Methods on this class are safe for use on any thread, but will return different values for different threads by design.
-
-
Field Summary
Fields Modifier and Type Field Description static String
CPU_TIME
static String
ENABLE_CPU_TIME
static String
LOCAL_CPU_TIME
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
beginContext(String context)
static boolean
isSupported()
static Optional<Long>
readMSandReset(String context)
static Optional<Long>
readNSAndReset(String context)
Get the number of nanoseconds since the last time this thread took a reading for the supplied context.static void
reset()
Cleanup method.static void
reset(String context)
Discard any accumulated time for a given context since the last invocation.String
toString()
-
-
-
Field Detail
-
CPU_TIME
public static final String CPU_TIME
- See Also:
- Constant Field Values
-
LOCAL_CPU_TIME
public static final String LOCAL_CPU_TIME
- See Also:
- Constant Field Values
-
ENABLE_CPU_TIME
public static final String ENABLE_CPU_TIME
- See Also:
- Constant Field Values
-
-
Method Detail
-
beginContext
public static void beginContext(String context)
-
isSupported
public static boolean isSupported()
-
readNSAndReset
public static Optional<Long> readNSAndReset(String context)
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
public static void reset(String context)
Discard any accumulated time for a given context since the last invocation.- Parameters:
context
- the context to reset
-
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.
-
-