@Exported public interface ThreadMXBean extends ThreadMXBean
This platform extension is only available to a thread implementation that supports this extension.
| Modifier and Type | Method and Description | 
|---|---|
| default ThreadInfo[] | dumpAllThreads(boolean lockedMonitors,
              boolean lockedSynchronizers,
              int maxDepth)Returns the thread info for all live threads
 with stack trace of the specified maximum number of elements
 and synchronization information. | 
| default long | getCurrentThreadAllocatedBytes()Returns an approximation of the total amount of memory, in bytes,
 allocated in heap memory for the current thread. | 
| long | getThreadAllocatedBytes(long id)Returns an approximation of the total amount of memory, in bytes,
 allocated in heap memory for the thread with the specified ID. | 
| long[] | getThreadAllocatedBytes(long[] ids)Returns an approximation of the total amount of memory, in bytes,
 allocated in heap memory for each thread whose ID is in the input
 array  ids. | 
| long[] | getThreadCpuTime(long[] ids)Returns the total CPU time for each thread whose ID is
 in the input array  idsin nanoseconds. | 
| default ThreadInfo[] | getThreadInfo(long[] ids,
             boolean lockedMonitors,
             boolean lockedSynchronizers,
             int maxDepth)Returns the thread info for each thread whose ID
 is in the input array ids,
 with stack trace of the specified maximum number of elements
 and synchronization information. | 
| long[] | getThreadUserTime(long[] ids)Returns the CPU time that each thread whose ID is in the input array
  idshas executed in user mode in nanoseconds. | 
| default long | getTotalThreadAllocatedBytes()Returns an approximation of the total amount of memory, in bytes, allocated
 in heap memory by all threads since the Java virtual machine started. | 
| boolean | isThreadAllocatedMemoryEnabled()Tests if thread memory allocation measurement is enabled. | 
| boolean | isThreadAllocatedMemorySupported()Tests if the Java virtual machine implementation supports thread memory
 allocation measurement. | 
| void | setThreadAllocatedMemoryEnabled(boolean enable)Enables or disables thread memory allocation measurement. | 
dumpAllThreads, findDeadlockedThreads, findMonitorDeadlockedThreads, getAllThreadIds, getCurrentThreadCpuTime, getCurrentThreadUserTime, getDaemonThreadCount, getPeakThreadCount, getThreadCount, getThreadCpuTime, getThreadInfo, getThreadInfo, getThreadInfo, getThreadInfo, getThreadInfo, getThreadUserTime, getTotalStartedThreadCount, isCurrentThreadCpuTimeSupported, isObjectMonitorUsageSupported, isSynchronizerUsageSupported, isThreadContentionMonitoringEnabled, isThreadContentionMonitoringSupported, isThreadCpuTimeEnabled, isThreadCpuTimeSupported, resetPeakThreadCount, setThreadContentionMonitoringEnabled, setThreadCpuTimeEnabledgetObjectNamelong[] getThreadCpuTime(long[] ids)
ids in nanoseconds.
 The returned values are of nanoseconds precision but
 not necessarily nanoseconds accuracy.
 
 This method is equivalent to calling the
 ThreadMXBean.getThreadCpuTime(long)
 method for each thread ID in the input array ids and setting the
 returned value in the corresponding element of the returned array.
ids - an array of thread IDs.-1 otherwise.NullPointerException - if ids is nullIllegalArgumentException - if any element in the input array
         ids is <= 0.UnsupportedOperationException - if the Java
         virtual machine implementation does not support CPU time
         measurement.ThreadMXBean.getThreadCpuTime(long), 
getThreadUserTime(long[]), 
ThreadMXBean.isThreadCpuTimeSupported(), 
ThreadMXBean.isThreadCpuTimeEnabled(), 
ThreadMXBean.setThreadCpuTimeEnabled(boolean)long[] getThreadUserTime(long[] ids)
ids has executed in user mode in nanoseconds.
 The returned values are of nanoseconds precision but
 not necessarily nanoseconds accuracy.
 
 This method is equivalent to calling the
 ThreadMXBean.getThreadUserTime(long)
 method for each thread ID in the input array ids and setting the
 returned value in the corresponding element of the returned array.
ids - an array of thread IDs.-1 otherwise.NullPointerException - if ids is nullIllegalArgumentException - if any element in the input array
         ids is <= 0.UnsupportedOperationException - if the Java
         virtual machine implementation does not support CPU time
         measurement.ThreadMXBean.getThreadUserTime(long), 
getThreadCpuTime(long[]), 
ThreadMXBean.isThreadCpuTimeSupported(), 
ThreadMXBean.isThreadCpuTimeEnabled(), 
ThreadMXBean.setThreadCpuTimeEnabled(boolean)default long getTotalThreadAllocatedBytes()
-1 otherwise.UnsupportedOperationException - if the Java virtual
         machine implementation does not support thread memory allocation
         measurement.isThreadAllocatedMemorySupported(), 
isThreadAllocatedMemoryEnabled(), 
setThreadAllocatedMemoryEnabled(boolean)default long getCurrentThreadAllocatedBytes()
This is a convenience method for local management use and is equivalent to calling:
getThreadAllocatedBytes(Thread.currentThread().getId());
-1 otherwise.UnsupportedOperationException - if the Java virtual
         machine implementation does not support thread memory allocation
         measurement.isThreadAllocatedMemorySupported(), 
isThreadAllocatedMemoryEnabled(), 
setThreadAllocatedMemoryEnabled(boolean)long getThreadAllocatedBytes(long id)
 If the thread with the specified ID is not alive or does not exist,
 this method returns -1. If thread memory allocation measurement
 is disabled, this method returns -1.
 A thread is alive if it has been started and has not yet died.
 
If thread memory allocation 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 thread memory allocation measurement starts.
id - the thread ID of a thread-1 otherwise.IllegalArgumentException - if id <= 0.UnsupportedOperationException - if the Java virtual
         machine implementation does not support thread memory allocation
         measurement.isThreadAllocatedMemorySupported(), 
isThreadAllocatedMemoryEnabled(), 
setThreadAllocatedMemoryEnabled(boolean)long[] getThreadAllocatedBytes(long[] ids)
ids.
 The returned values are approximations because some Java virtual machine
 implementations may use object allocation mechanisms that result in a
 delay between the time an object is allocated and the time its size is
 recorded.
 
 This method is equivalent to calling the
 getThreadAllocatedBytes(long)
 method for each thread ID in the input array ids and setting the
 returned value in the corresponding element of the returned array.
ids - an array of thread IDs.NullPointerException - if ids is nullIllegalArgumentException - if any element in the input array
         ids is <= 0.UnsupportedOperationException - if the Java virtual
         machine implementation does not support thread memory allocation
         measurement.getThreadAllocatedBytes(long), 
isThreadAllocatedMemorySupported(), 
isThreadAllocatedMemoryEnabled(), 
setThreadAllocatedMemoryEnabled(boolean)boolean isThreadAllocatedMemorySupported()
true
     if the Java virtual machine implementation supports thread memory
     allocation measurement;
   false otherwise.boolean isThreadAllocatedMemoryEnabled()
true if thread memory allocation measurement is enabled;
         false otherwise.UnsupportedOperationException - if the Java virtual
         machine does not support thread memory allocation measurement.isThreadAllocatedMemorySupported()void setThreadAllocatedMemoryEnabled(boolean enable)
enable - true to enable;
               false to disable.UnsupportedOperationException - if the Java virtual
         machine does not support thread memory allocation measurement.SecurityException - if a security manager
         exists and the caller does not have
         ManagementPermission("control").isThreadAllocatedMemorySupported()default ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors, boolean lockedSynchronizers, int maxDepth)
This method obtains a snapshot of the thread information for each thread including:
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.
If a thread does not lock any object monitor or lockedMonitors is false, the returned ThreadInfo object will have an empty MonitorInfo array. Similarly, if a thread does not lock any synchronizer or lockedSynchronizers is false, the returned ThreadInfo object will have an empty LockInfo array.
When both lockedMonitors and lockedSynchronizers parameters are false, it is equivalent to calling:
     getThreadInfo(ids, maxDepth)
 This method is designed for troubleshooting use, but not for synchronization control. It might be an expensive operation.
 MBeanServer access:
 The mapped type of ThreadInfo is
 CompositeData with attributes as specified in the
 ThreadInfo.from method.
ids - an array of thread IDs.lockedMonitors - if true, retrieves all locked monitors.lockedSynchronizers - if true, retrieves all locked
             ownable synchronizers.maxDepth - indicates the maximum number of
 StackTraceElement to be retrieved from the stack trace.ThreadInfo objects, each containing
 information about a thread whose ID is in the corresponding
 element of the input array of IDs.IllegalArgumentException - if maxDepth is negative.SecurityException - if a security manager
         exists and the caller does not have
         ManagementPermission("monitor").UnsupportedOperationException - ThreadMXBean.isObjectMonitorUsageSupported(), 
ThreadMXBean.isSynchronizerUsageSupported()default ThreadInfo[] dumpAllThreads(boolean lockedMonitors, boolean lockedSynchronizers, int maxDepth)
 This method returns an array of ThreadInfo objects
 as specified in the getThreadInfo(long[], boolean, boolean, int)
 method.
lockedMonitors - if true, dump all locked monitors.lockedSynchronizers - if true, dump all locked
             ownable synchronizers.maxDepth - indicates the maximum number of
 StackTraceElement to be retrieved from the stack trace.ThreadInfo for all live threads.IllegalArgumentException - if maxDepth is negative.SecurityException - if a security manager
         exists and the caller does not have
         ManagementPermission("monitor").UnsupportedOperationException - ThreadMXBean.isObjectMonitorUsageSupported(), 
ThreadMXBean.isSynchronizerUsageSupported()
 Copyright © 2003, 2025, Oracle and/or its affiliates.  All rights reserved.