The management interface for the thread system of
the Java virtual machine.
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
Thread ID
Thread ID is a positive long value returned by calling the
Thread.getId()
method for a thread.
The thread ID is unique during its lifetime. When a thread
is terminated, this thread ID may be reused.
Some methods in this interface take a thread ID or an array
of thread IDs as the input parameter and return per-thread information.
Thread CPU time
A Java virtual machine implementation may support measuring
the CPU time for the current thread, for any thread, or for no threads.
The ThreadMXBean.isThreadCpuTimeSupported()
method can be used to determine
if a Java virtual machine supports measuring of the CPU time for any
thread. The ThreadMXBean.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 ThreadMXBean.isThreadCpuTimeEnabled()
and ThreadMXBean.setThreadCpuTimeEnabled(boolean)
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.
Thread Contention Monitoring
Some Java virtual machines may support thread contention monitoring.
When thread contention monitoring is enabled, the accumulated elapsed
time that the thread has blocked for synchronization or waited for
notification will be collected and returned in the
ThreadInfo object.
The ThreadMXBean.isThreadContentionMonitoringSupported()
method can be used to
determine if a Java virtual machine supports thread contention monitoring.
The thread contention monitoring is disabled by default. The
ThreadMXBean.setThreadContentionMonitoringEnabled(boolean)
method can be used to enable
thread contention monitoring.
Synchronization Information and Deadlock Detection
Some Java virtual machines may support monitoring of
object monitor usage and
ownable synchronizer usage.
The
ThreadMXBean.getThreadInfo(long[], boolean, boolean)
and
ThreadMXBean.dumpAllThreads(boolean, boolean)
methods can be used to obtain the thread stack trace
and synchronization information including which
lock a thread is blocked to
acquire or waiting on and which locks the thread currently owns.
The ThreadMXBean interface provides the
ThreadMXBean.findMonitorDeadlockedThreads()
and
ThreadMXBean.findDeadlockedThreads()
methods to find deadlocks in
the running application.