PlatformManagedObject
, ThreadMXBean
public interface ThreadMXBean extends ThreadMXBean
This platform extension is only available to a thread implementation that supports this extension.
Modifier and Type | Method | Description |
---|---|---|
default long |
getCurrentThreadAllocatedBytes() |
Returns an approximation of the total amount of memory, in bytes, allocated in heap memory for the current thread. |
long |
getThreadAllocatedBytes |
Returns an approximation of the total amount of memory, in bytes, allocated in heap memory for the thread with the specified ID. |
long[] |
getThreadAllocatedBytes |
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 |
Returns the total CPU time for each thread whose ID is in the input array ids in nanoseconds. |
long[] |
getThreadUserTime |
Returns the CPU time that each thread whose ID is in the input array ids has 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 |
Enables or disables thread memory allocation measurement. |
getObjectName
dumpAllThreads, dumpAllThreads, findDeadlockedThreads, findMonitorDeadlockedThreads, getAllThreadIds, getCurrentThreadCpuTime, getCurrentThreadUserTime, getDaemonThreadCount, getPeakThreadCount, getThreadCount, getThreadCpuTime, getThreadInfo, getThreadInfo, getThreadInfo, getThreadInfo, getThreadInfo, getThreadInfo, getThreadUserTime, getTotalStartedThreadCount, isCurrentThreadCpuTimeSupported, isObjectMonitorUsageSupported, isSynchronizerUsageSupported, isThreadContentionMonitoringEnabled, isThreadContentionMonitoringSupported, isThreadCpuTimeEnabled, isThreadCpuTimeSupported, resetPeakThreadCount, setThreadContentionMonitoringEnabled, setThreadCpuTimeEnabled
long[] 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 null
IllegalArgumentException
- if any element in the input array ids
is <=
0
.UnsupportedOperationException
- if the Java virtual machine implementation does not support CPU time measurement.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 null
IllegalArgumentException
- if any element in the input array ids
is <=
0
.UnsupportedOperationException
- if the Java virtual machine implementation does not support CPU time measurement.default long getTotalThreadAllocatedBytes()
UnsupportedOperationException
if the Java virtual machine implementation does not support thread memory allocation measurement, and otherwise acts as though thread memory allocation measurement is disabled.-1
otherwise.UnsupportedOperationException
- if the Java virtual machine implementation does not support thread memory allocation measurement.default long getCurrentThreadAllocatedBytes()
This is a convenience method for local management use and is equivalent to calling:
getThreadAllocatedBytes
(Thread.currentThread().threadId());
-1
otherwise.UnsupportedOperationException
- if the Java virtual machine implementation does not support thread memory allocation measurement.long getThreadAllocatedBytes(long id)
If the thread with the specified ID is a virtual thread, 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 terminated.
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.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 null
IllegalArgumentException
- if any element in the input array ids
is <=
0
.UnsupportedOperationException
- if the Java virtual machine implementation does not support thread memory allocation measurement.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.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").
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.management/com/sun/management/ThreadMXBean.html