java.lang.management
public class ThreadInfo extends Object
A class which maintains information about a particular thread. This information includes:
Since: 1.5
See Also: isThreadContentionMonitoringSupported
Method Summary | |
---|---|
static ThreadInfo | from(CompositeData data) Returns a {@link ThreadInfo} instance using the values given in the supplied {@link javax.management.openmbean.CompositeData} object. |
long | getBlockedCount()
Returns the number of times this thread has been
in the {@link java.lang.Thread.State#BLOCKED} state.
|
long | getBlockedTime() Returns the accumulated number of milliseconds this thread has been in the {@link java.lang.Thread.State#BLOCKED} state since thread contention monitoring was last enabled. |
String | getLockName() Returns a {@link java.lang.String} representation of the monitor lock on which this thread is blocked. |
long | getLockOwnerId()
Returns the identifier of the thread which owns the
monitor lock this thread is waiting for. |
String | getLockOwnerName()
Returns the name of the thread which owns the
monitor lock this thread is waiting for. |
StackTraceElement[] | getStackTrace() Returns the stack trace of this thread to the depth specified on creation of this {@link ThreadInfo} object. |
long | getThreadId()
Returns the identifier of the thread associated with
this instance of {@link ThreadInfo}.
|
String | getThreadName()
Returns the name of the thread associated with
this instance of {@link ThreadInfo}.
|
Thread.State | getThreadState()
Returns the state of the thread associated with
this instance of {@link ThreadInfo}.
|
long | getWaitedCount()
Returns the number of times this thread has been
in the {@link java.lang.Thread.State#WAITING}
or {@link java.lang.Thread.State#TIMED_WAITING} state.
|
long | getWaitedTime() Returns the accumulated number of milliseconds this thread has been in the {@link java.lang.Thread.State#WAITING} or {@link java.lang.Thread.State#TIMED_WAITING} state, since thread contention monitoring was last enabled. |
boolean | isInNative()
Returns true if the thread is in a native method. |
boolean | isSuspended()
Returns true if the thread has been suspended using
{@link java.lang.Thread#suspend()}.
|
String | toString()
Returns a {@link java.lang.String} representation of
this {@link ThreadInfo} object. |
Returns a {@link ThreadInfo} instance using the values given in the supplied {@link javax.management.openmbean.CompositeData} object. The composite data instance should contain the following attributes with the specified types:
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 |
lockName | java.lang.String |
lockOwnerId | java.lang.Long |
lockOwnerName | java.lang.String |
stackTrace | javax.management.openmbean.CompositeData[] |
The stack trace is further described as:
Name | Type |
className | java.lang.String |
methodName | java.lang.String |
fileName | java.lang.String |
lineNumber | java.lang.Integer |
nativeMethod | java.lang.Boolean |
Parameters: data the composite data structure to take values from.
Returns: a new instance containing the values from the
composite data structure, or null
if the data structure was also null
.
Throws: IllegalArgumentException if the composite data structure does not match the structure outlined above.
Returns: the number of times this thread has been blocked.
Returns the accumulated number of milliseconds this thread has been in the {@link java.lang.Thread.State#BLOCKED} state since thread contention monitoring was last enabled. A thread enters this state when it is waiting to obtain an object's monitor. This may occur either on entering a synchronized method for the first time, or on re-entering it following a call to {@link java.lang.Object#wait()}.
Use of this method requires virtual machine support for thread contention monitoring and for this support to be enabled.
Returns: the accumulated time (in milliseconds) that this thread has spent in the blocked state, since thread contention monitoring was enabled, or -1 if thread contention monitoring is disabled.
Throws: UnsupportedOperationException if the virtual machine does not support contention monitoring.
See Also: isThreadContentionMonitoringEnabled isThreadContentionMonitoringSupported
Returns a {@link java.lang.String} representation of
the monitor lock on which this thread is blocked. If
the thread is not blocked, this method returns
null
.
The returned {@link java.lang.String} is constructed
using the class name and identity hashcode (usually
the memory address of the object) of the lock. The
two are separated by the '@' character, and the identity
hashcode is represented in hexadecimal. Thus, for a
lock, l
, the returned value is
the result of concatenating
l.getClass().getName()
, "@"
and
Integer.toHexString(System.identityHashCode(l))
.
The value is only unique to the extent that the identity
hash code is also unique.
Returns: a string representing the lock on which this
thread is blocked, or null
if
the thread is not blocked.
Returns: the thread identifier of thread holding the lock this thread is waiting for, or -1 if the thread is not blocked or the lock is not held by another thread.
null
is returned if either this thread is not blocked,
or the lock is not held by any other thread.
Returns: the thread identifier of thread holding the lock
this thread is waiting for, or null
if the thread is not blocked or the lock is not
held by another thread.
Returns the stack trace of this thread to the depth specified on creation of this {@link ThreadInfo} object. If the depth is zero, an empty array will be returned. For non-zero arrays, the elements start with the most recent trace at position zero. The bottom of the stack represents the oldest method invocation which meets the depth requirements.
Some virtual machines may not be able to return stack trace information for a thread. In these cases, an empty array will also be returned.
Returns: an array of {@link java.lang.StackTraceElement}s representing the trace of this thread.
Returns: the thread's identifier.
Returns: the thread's name.
Returns: the thread's state.
Returns: the number of times this thread has been waiting.
Returns the accumulated number of milliseconds this thread has been in the {@link java.lang.Thread.State#WAITING} or {@link java.lang.Thread.State#TIMED_WAITING} state, since thread contention monitoring was last enabled. A thread enters one of these states when it is waiting due to a call to {@link java.lang.Object.wait()}, {@link java.lang.Object.join()} or {@link java.lang.concurrent.locks.LockSupport.park()}, either with an infinite or timed delay, respectively.
Use of this method requires virtual machine support for thread contention monitoring and for this support to be enabled.
Returns: the accumulated time (in milliseconds) that this thread has spent in one of the waiting states, since thread contention monitoring was enabled, or -1 if thread contention monitoring is disabled.
Throws: UnsupportedOperationException if the virtual machine does not support contention monitoring.
See Also: isThreadContentionMonitoringEnabled isThreadContentionMonitoringSupported
Returns: true if the thread is in a native method, false otherwise.
Returns: true if the thread is suspended, false otherwise.
java.lang.management.ThreadInfo[id=tid, name=n,
state=s, blockedCount=bc, waitedCount=wc, isInNative=iin,
isSuspended=is]
, where tid
is
the thread identifier, n
is the
thread name, s
is the thread state,
bc
is the blocked state count,
wc
is the waiting state count and
iin
and is
are boolean
flags to indicate the thread is in native code or
suspended respectively. If the thread is blocked,
lock=l, lockOwner=lo
is also included,
where l
is the lock waited for, and
lo
is the thread which owns the lock
(or null if there is no owner).
Returns: the string specified above.