public class ThreadInfo extends Object
ThreadInfo
contains the information about a thread including: Object.wait
method, orLockSupport.park
call.thread contention monitoring
was enabled. Some Java virtual machine implementation may not support this. The ThreadMXBean.isThreadContentionMonitoringSupported()
method can be used to determine if a Java virtual machine supports this.This thread information class is designed for use in monitoring of the system, not for synchronization control.
ThreadInfo
is mapped to a CompositeData
with attributes as specified in the from
method.Modifier and Type | Method | Description |
---|---|---|
static ThreadInfo |
from |
Returns a ThreadInfo object represented by the given CompositeData . |
long |
getBlockedCount() |
Returns the total number of times that the thread associated with this ThreadInfo blocked to enter or reenter a monitor. |
long |
getBlockedTime() |
Returns the approximate accumulated elapsed time (in milliseconds) that the thread associated with this ThreadInfo has blocked to enter or reenter a monitor since thread contention monitoring is enabled. |
MonitorInfo[] |
getLockedMonitors() |
Returns an array of MonitorInfo objects, each of which represents an object monitor currently locked by the thread associated with this ThreadInfo . |
LockInfo[] |
getLockedSynchronizers() |
Returns an array of LockInfo objects, each of which represents an ownable synchronizer currently locked by the thread associated with this ThreadInfo . |
LockInfo |
getLockInfo() |
Returns the LockInfo of an object for which the thread associated with this ThreadInfo is blocked waiting. |
String |
getLockName() |
Returns the string representation of an object for which the thread associated with this ThreadInfo is blocked waiting. |
long |
getLockOwnerId() |
Returns the ID of the thread which owns the object for which the thread associated with this ThreadInfo is blocked waiting. |
String |
getLockOwnerName() |
Returns the name of the thread which owns the object for which the thread associated with this ThreadInfo is blocked waiting. |
int |
getPriority() |
Returns the thread priority of the thread associated with this ThreadInfo . |
StackTraceElement[] |
getStackTrace() |
Returns the stack trace of the thread associated with this ThreadInfo . |
long |
getThreadId() |
Returns the ID of the thread associated with this ThreadInfo . |
String |
getThreadName() |
Returns the name of the thread associated with this ThreadInfo . |
Thread.State |
getThreadState() |
Returns the state of the thread associated with this ThreadInfo . |
long |
getWaitedCount() |
Returns the total number of times that the thread associated with this ThreadInfo waited for notification. |
long |
getWaitedTime() |
Returns the approximate accumulated elapsed time (in milliseconds) that the thread associated with this ThreadInfo has waited for notification since thread contention monitoring is enabled. |
boolean |
isDaemon() |
Tests if the thread associated with this ThreadInfo is a daemon thread. |
boolean |
isInNative() |
Tests if the thread associated with this ThreadInfo is executing native code via the Java Native Interface (JNI). |
boolean |
isSuspended() |
Tests if the thread associated with this ThreadInfo is suspended. |
String |
toString() |
Returns a string representation of this thread info. |
public long getThreadId()
ThreadInfo
.public String getThreadName()
ThreadInfo
.public Thread.State getThreadState()
ThreadInfo
.Thread.State
of the associated thread.public long getBlockedTime()
ThreadInfo
has blocked to enter or reenter a monitor since thread contention monitoring is enabled. I.e. the total accumulated time the thread has been in the BLOCKED
state since thread contention monitoring was last enabled. This method returns -1
if thread contention monitoring is disabled. The Java virtual machine may measure the time with a high resolution timer. This statistic is reset when the thread contention monitoring is re-enabled.
BLOCKED
state; -1
if thread contention monitoring is disabled.UnsupportedOperationException
- if the Java virtual machine does not support this operation.public long getBlockedCount()
ThreadInfo
blocked to enter or reenter a monitor. I.e. the number of times a thread has been in the BLOCKED
state.BLOCKED
state.public long getWaitedTime()
ThreadInfo
has waited for notification since thread contention monitoring is enabled. I.e. the total accumulated time the thread has been in the WAITING
or TIMED_WAITING
state since thread contention monitoring is enabled. This method returns -1
if thread contention monitoring is disabled. The Java virtual machine may measure the time with a high resolution timer. This statistic is reset when the thread contention monitoring is re-enabled.
WAITING
or TIMED_WAITING
state; -1
if thread contention monitoring is disabled.UnsupportedOperationException
- if the Java virtual machine does not support this operation.public long getWaitedCount()
ThreadInfo
waited for notification. I.e. the number of times that a thread has been in the WAITING
or TIMED_WAITING
state.WAITING
or TIMED_WAITING
state.public LockInfo getLockInfo()
LockInfo
of an object for which the thread associated with this ThreadInfo
is blocked waiting. A thread can be blocked waiting for one of the following: BLOCKED
state waiting to enter the synchronized
statement or method. WAITING
or TIMED_WAITING
state due to a call to the Object.wait
method. WAITING
or TIMED_WAITING
state due to a call to the LockSupport.park
method. The synchronization object is the object returned from LockSupport.getBlocker
method. Typically it is an ownable synchronizer or a Condition
.This method returns null
if the thread is not in any of the above conditions.
LockInfo
of an object for which the thread is blocked waiting if any; null
otherwise.public String getLockName()
string representation
of an object for which the thread associated with this ThreadInfo
is blocked waiting. This method is equivalent to calling: getLockInfo().toString()
This method will return null
if this thread is not blocked waiting for any object or if the object is not owned by any thread.
null
otherwise.public long getLockOwnerId()
ThreadInfo
is blocked waiting. This method will return -1
if this thread is not blocked waiting for any object or if the object is not owned by any thread.-1
if this thread is not blocked or if the object is not owned by any thread.public String getLockOwnerName()
ThreadInfo
is blocked waiting. This method will return null
if this thread is not blocked waiting for any object or if the object is not owned by any thread.null
if this thread is not blocked or if the object is not owned by any thread.public StackTraceElement[] getStackTrace()
ThreadInfo
. If no stack trace was requested for this thread info, this method will return a zero-length array. If the returned array is of non-zero length then the first element of the array represents the top of the stack, which is the most recent method invocation in the sequence. The last element of the array represents the bottom of the stack, which is the least recent method invocation in the sequence. Some Java virtual machines may, under some circumstances, omit one or more stack frames from the stack trace. In the extreme case, a virtual machine that has no stack trace information concerning the thread associated with this ThreadInfo
is permitted to return a zero-length array from this method.
StackTraceElement
objects of the thread.public boolean isSuspended()
ThreadInfo
is suspended. This method returns true
if Thread.suspend()
has been called.true
if the thread is suspended; false
otherwise.public boolean isInNative()
ThreadInfo
is executing native code via the Java Native Interface (JNI). The JNI native code does not include the virtual machine support code or the compiled native code generated by the virtual machine.true
if the thread is executing native code; false
otherwise.public boolean isDaemon()
ThreadInfo
is a daemon thread.true
if the thread is a daemon thread, false
otherwise.public int getPriority()
ThreadInfo
.ThreadInfo
.public String toString()
public static ThreadInfo from(CompositeData cd)
ThreadInfo
object represented by the given CompositeData
. A CompositeData
representing a ThreadInfo
of version N must contain all of the attributes defined in version ≤ N unless specified otherwise. The same rule applies the composite type of the given CompositeData
and transitively to attributes whose type or component type is CompositeType
. A CompositeData
representing ThreadInfo
of version N contains "stackTrace"
attribute and "lockedMonitors"
attribute representing an array of StackTraceElement
and an array of MonitorInfo
respectively and their types are of version N. The "lockedStackFrame"
attribute in MonitorInfo
's composite type must represent StackTraceElement
of the same version N. Otherwise, this method will throw IllegalArgumentException
.
Attribute Name | Type | Since |
---|---|---|
threadId | java.lang.Long | 5 |
threadName | java.lang.String | 5 |
threadState | java.lang.String | 5 |
suspended | java.lang.Boolean | 5 |
inNative | java.lang.Boolean | 5 |
blockedCount | java.lang.Long | 5 |
blockedTime | java.lang.Long | 5 |
waitedCount | java.lang.Long | 5 |
waitedTime | java.lang.Long | 5 |
lockName | java.lang.String | 5 |
lockOwnerId | java.lang.Long | 5 |
lockOwnerName | java.lang.String | 5 |
stackTrace |
javax.management.openmbean.CompositeData[] , each element is a CompositeData representing StackTraceElement as specified below. | 5 |
lockInfo |
javax.management.openmbean.CompositeData - the mapped type for LockInfo as specified in the LockInfo.from(javax.management.openmbean.CompositeData) method. If the given | 6 |
lockedMonitors |
javax.management.openmbean.CompositeData[] whose element type is the mapped type for MonitorInfo as specified in the MonitorInfo.from method. If the given | 6 |
lockedSynchronizers |
javax.management.openmbean.CompositeData[] whose element type is the mapped type for LockInfo as specified in the LockInfo.from(javax.management.openmbean.CompositeData) method. If the given | 6 |
daemon |
java.lang.Boolean If the given | 9 |
priority |
java.lang.Integer If the given | 9 |
CompositeData
representing StackTraceElement
of version N must contain all of the attributes defined in version ≤ N unless specified otherwise. Attribute Name | Type | Since |
---|---|---|
classLoaderName | java.lang.String | 9 |
moduleName | java.lang.String | 9 |
moduleVersion | java.lang.String | 9 |
className | java.lang.String | 5 |
methodName | java.lang.String | 5 |
fileName | java.lang.String | 5 |
lineNumber | java.lang.Integer | 5 |
nativeMethod | java.lang.Boolean | 5 |
cd
- CompositeData
representing a ThreadInfo
ThreadInfo
object represented by cd
if cd
is not null
; null
otherwise.IllegalArgumentException
- if the given cd
and its composite type does not contain all of the attributes defined for a ThreadInfo
of a specific runtime version.public MonitorInfo[] getLockedMonitors()
MonitorInfo
objects, each of which represents an object monitor currently locked by the thread associated with this ThreadInfo
. If no locked monitor was requested for this thread info or no monitor is locked by the thread, this method will return a zero-length array.MonitorInfo
objects representing the object monitors locked by the thread.public LockInfo[] getLockedSynchronizers()
LockInfo
objects, each of which represents an ownable synchronizer currently locked by the thread associated with this ThreadInfo
. If no locked synchronizer was requested for this thread info or no synchronizer is locked by the thread, this method will return a zero-length array.LockInfo
objects representing the ownable synchronizers locked by the thread.
© 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/java.management/java/lang/management/ThreadInfo.html