public class ThreadInfo extends Object
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.
CompositeData
with attributes as specified in
the from
method.ThreadMXBean.getThreadInfo(long)
,
ThreadMXBean.dumpAllThreads(boolean, boolean)
Modifier and Type | Method and Description |
---|---|
static ThreadInfo |
from(CompositeData cd)
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.
|
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 |
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()
public String getThreadName()
public Thread.State getThreadState()
public long getBlockedTime()
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 reenabled.
UnsupportedOperationException
- if the Java
virtual machine does not support this operation.ThreadMXBean.isThreadContentionMonitoringSupported()
,
ThreadMXBean.setThreadContentionMonitoringEnabled(boolean)
public long getBlockedCount()
BLOCKED
state.public long getWaitedTime()
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 reenabled.
UnsupportedOperationException
- if the Java
virtual machine does not support this operation.ThreadMXBean.isThreadContentionMonitoringSupported()
,
ThreadMXBean.setThreadContentionMonitoringEnabled(boolean)
public long getWaitedCount()
WAITING
or TIMED_WAITING
state.public LockInfo getLockInfo()
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.
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.
getLockInfo()
public long getLockOwnerId()
getLockInfo()
public String getLockOwnerName()
getLockInfo()
public StackTraceElement[] getStackTrace()
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.
public boolean isSuspended()
Thread.suspend()
has been called.public boolean isInNative()
public String toString()
public static ThreadInfo from(CompositeData cd)
Attribute Name Type threadId java.lang.Long threadName java.lang.String threadState java.lang.String suspended java.lang.Boolean inNative java.lang.Boolean blockedCount java.lang.Long blockedTime java.lang.Long waitedCount java.lang.Long waitedTime java.lang.Long lockInfo javax.management.openmbean.CompositeData - the mapped type for LockInfo
as specified in theLockInfo.from(javax.management.openmbean.CompositeData)
method.If cd does not contain this attribute, the LockInfo object will be constructed from the value of the lockName attribute.
lockName java.lang.String lockOwnerId java.lang.Long lockOwnerName java.lang.String stackTrace javax.management.openmbean.CompositeData[] Each element is a CompositeData representing StackTraceElement containing the following attributes:
Attribute Name Type className java.lang.String methodName java.lang.String fileName java.lang.String lineNumber java.lang.Integer nativeMethod java.lang.Boolean lockedMonitors javax.management.openmbean.CompositeData[] whose element type is the mapped type for MonitorInfo
as specified in theMonitor.from
method.If cd does not contain this attribute, this attribute will be set to an empty array.
lockedSynchronizers javax.management.openmbean.CompositeData[] whose element type is the mapped type for LockInfo
as specified in theLockInfo.from(javax.management.openmbean.CompositeData)
method.If cd does not contain this attribute, this attribute will be set to an empty array.
cd
- CompositeData representing a ThreadInfoIllegalArgumentException
- if cd does not
represent a ThreadInfo with the attributes described
above.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.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. Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2022, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.