A Java virtual machine has a single instance of the implementation class of this interface. This instance implementing this interface is an MXBean that can be obtained by calling the ManagementFactory#getThreadMXBean method or from the platform MBeanServer method.
The ObjectName for uniquely identifying the MXBean for the thread system within an MBeanServer is:
java.lang:type=Threading
Some methods in this interface take a thread ID or an array of thread IDs as the input parameter and return per-thread information.
The #isThreadCpuTimeSupported method can be used to determine if a Java virtual machine supports measuring of the CPU time for any thread. The #isCurrentThreadCpuTimeSupported method can be used to determine if a Java virtual machine supports measuring of the CPU time for the current thread. A Java virtual machine implementation that supports CPU time measurement for any thread will also support that for the current thread.
The CPU time provided by this interface has nanosecond precision but not necessarily nanosecond accuracy.
A Java virtual machine may disable CPU time measurement by default. The #isThreadCpuTimeEnabled and #setThreadCpuTimeEnabled methods can be used to test if CPU time measurement is enabled and to enable/disable this support respectively. Enabling thread CPU measurement could be expensive in some Java virtual machine implementations.
More formally, a thread is monitor deadlocked if it is part of a cycle in the relation "is waiting for an object monitor owned by". In the simplest case, thread A is blocked waiting for a monitor owned by thread B, and thread B is blocked waiting for a monitor owned by thread A.
This method is designed for troubleshooting use, but not for synchronization control. It might be an expensive operation.
This is a convenient method for local management use and is equivalent to calling:
getThreadCpuTime
(Thread.currentThread().getId());
This is a convenient method for local management use and is equivalent to calling:
getThreadUserTime
(Thread.currentThread().getId());
If the thread of the specified ID is not alive or does not exist, this method returns -1. If CPU time measurement is disabled, this method returns -1. A thread is alive if it has been started and has not yet died.
If CPU time measurement is enabled after the thread has started, the Java virtual machine implementation may choose any time up to and including the time that the capability is enabled as the point where CPU time measurement starts.
getThreadInfo(id, 0);
This method returns a ThreadInfo object representing the thread information for the thread of the specified ID. The stack trace in the returned ThreadInfo object will be an empty array of StackTraceElement. If a thread of the given ID is not alive or does not exist, this method will return null. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in
ThreadInfo
.
getThreadInfo
(ids, 0);
This method returns an array of the ThreadInfo objects. The stack trace in each ThreadInfo object will be an empty array of StackTraceElement. If a thread of a given ID is not alive or does not exist, the corresponding element in the returned array will contain null. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in
ThreadInfo
.
When the Java virtual machine has no stack trace information about a thread or maxDepth == 0, the stack trace in the ThreadInfo object will be an empty array of StackTraceElement.
This method returns an array of the ThreadInfo objects, each is the thread information about the thread with the same index as in the ids array. If a thread of the given ID is not alive or does not exist, null will be set in the corresponding element in the returned array. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in
ThreadInfo
.
When the Java virtual machine has no stack trace information about a thread or maxDepth == 0, the stack trace in the ThreadInfo object will be an empty array of StackTraceElement.
If a thread of the given ID is not alive or does not exist, this method will return null. A thread is alive if it has been started and has not yet died.
MBeanServer access:
The mapped type of ThreadInfo is
CompositeData with attributes as specified in
ThreadInfo
.
If the thread of the specified ID is not alive or does not exist, this method returns -1. If CPU time measurement is disabled, this method returns -1. A thread is alive if it has been started and has not yet died.
If CPU time measurement is enabled after the thread has started, the Java virtual machine implementation may choose any time up to and including the time that the capability is enabled as the point where CPU time measurement starts.