- java.lang.Object
-
- java.lang.management.ThreadInfo
-
public class ThreadInfo extends Object
Information about a snapshot of the state of a thread.- Since:
- 1.5
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ThreadInfofrom(CompositeData cd)Receives aCompositeDatarepresenting aThreadInfoobject and attempts to return the rootThreadInfoinstance.longgetBlockedCount()Returns the number of times that the thread represented by thisThreadInfohas been blocked on any monitor objects.longgetBlockedTime()If thread contention monitoring is supported and enabled, returns the total amount of time that the thread represented by thisThreadInfohas spent blocked on any monitor objects.MonitorInfo[]getLockedMonitors()Returns an array ofMonitorInfoobjects, one for every monitor object locked by theThreadcorresponding to thisThreadInfowhen it was instantiated.LockInfo[]getLockedSynchronizers()Returns an array ofLockInfoobjects, each one containing information on an ownable synchronizer (a synchronizer that makes use of theAbstractOwnableSynchronizertype and which is completely owned by a single thread) locked by theThreadcorresponding to thisThreadInfowhen it was instantiated.LockInfogetLockInfo()If the thread corresponding to thisThreadInfois blocked then this method returns aLockInfoobject that contains details of the associated lock object.StringgetLockName()If the thread represented by thisThreadInfois currently blocked on or waiting on a monitor object, returns a string representation of that monitor object.longgetLockOwnerId()If the thread represented by thisThreadInfois currently blocked on or waiting on a monitor object, returns the thread identifier of the thread which owns the monitor.StringgetLockOwnerName()If the thread represented by thisThreadInfois currently blocked on or waiting on a monitor object, returns the name of the thread which owns the monitor.intgetPriority()Returns the thread priority of the thread represented by thisThreadInfo.StackTraceElement[]getStackTrace()If available, returns the stack trace for the thread represented by thisThreadInfoinstance.longgetThreadId()Returns the thread identifier of the thread represented by thisThreadInfo.StringgetThreadName()Returns the name of the thread represented by thisThreadInfo.Thread.StategetThreadState()Returns the thread state value of the thread represented by thisThreadInfo.longgetWaitedCount()The number of times that the thread represented by thisThreadInfohas gone to the "wait" or "timed wait" state.longgetWaitedTime()If thread contention monitoring is supported and enabled, returns the total amount of time that the thread represented by thisThreadInfohas spent waiting for notifications.booleanisDaemon()Returns abooleanindication of whether or not the thread represented by thisThreadInfois currently a daemon thread.booleanisInNative()Returns abooleanindication of whether or not the thread represented by thisThreadInfois currently in a native method.booleanisSuspended()Returns abooleanindication of whether or not the thread represented by thisThreadInfois currently suspended.StringtoString()Answers a string containing a concise, human-readable description of the receiver.
-
-
-
Method Detail
-
getBlockedCount
public long getBlockedCount()
Returns the number of times that the thread represented by thisThreadInfohas been blocked on any monitor objects. The count is from the start of the thread's life.- Returns:
- the number of times the corresponding thread has been blocked on a monitor.
-
getBlockedTime
public long getBlockedTime()
If thread contention monitoring is supported and enabled, returns the total amount of time that the thread represented by thisThreadInfohas spent blocked on any monitor objects. The time is measured in milliseconds and will be measured over the time period since thread contention was most recently enabled.- Returns:
- if thread contention monitoring is currently enabled, the number
of milliseconds that the thread associated with this
ThreadInfohas spent blocked on any monitors. If thread contention monitoring is supported but currently disabled,-1. - Throws:
UnsupportedOperationException- if the virtual machine does not support thread contention monitoring.- See Also:
ThreadMXBean.isThreadContentionMonitoringSupported(),ThreadMXBean.isThreadContentionMonitoringEnabled()
-
getLockName
public String getLockName()
If the thread represented by thisThreadInfois currently blocked on or waiting on a monitor object, returns a string representation of that monitor object.The monitor's string representation is comprised of the following component parts:
monitorclass name@Integer.toHexString(System.identityHashCode(monitor))
- Returns:
- if blocked or waiting on a monitor, a string representation of
the monitor object. Otherwise,
null. - See Also:
Integer.toHexString(int),System.identityHashCode(java.lang.Object)
-
getLockOwnerId
public long getLockOwnerId()
If the thread represented by thisThreadInfois currently blocked on or waiting on a monitor object, returns the thread identifier of the thread which owns the monitor.- Returns:
- the thread identifier of the other thread which holds the monitor
that the thread associated with this
ThreadInfois blocked or waiting on. If thisThreadInfo's associated thread is currently not blocked or waiting, or there is no other thread holding the monitor, returns a-1.
-
getLockOwnerName
public String getLockOwnerName()
If the thread represented by thisThreadInfois currently blocked on or waiting on a monitor object, returns the name of the thread which owns the monitor.- Returns:
- the name of the other thread which holds the monitor that the
thread associated with this
ThreadInfois blocked or waiting on. If thisThreadInfo's associated thread is currently not blocked or waiting, or there is no other thread holding the monitor, returns anullreference.
-
getLockInfo
public LockInfo getLockInfo()
If the thread corresponding to thisThreadInfois blocked then this method returns aLockInfoobject that contains details of the associated lock object.- Returns:
- a
LockInfoobject if thisThreadInfo's thread is currently blocked, elsenull.
-
getStackTrace
public StackTraceElement[] getStackTrace()
If available, returns the stack trace for the thread represented by thisThreadInfoinstance. The stack trace is returned in an array ofStackTraceElementobjects with the "top" of the stack encapsulated in the first array element and the "bottom" of the stack in the last array element.If this
ThreadInfowas created without any stack trace information (e.g. by a call toThreadMXBean.getThreadInfo(long)) then the returned array will have a length of zero.- Returns:
- the stack trace for the thread represented by this
ThreadInfo.
-
getThreadId
public long getThreadId()
Returns the thread identifier of the thread represented by thisThreadInfo.- Returns:
- the identifier of the thread corresponding to this
ThreadInfo.
-
getThreadName
public String getThreadName()
Returns the name of the thread represented by thisThreadInfo.- Returns:
- the name of the thread corresponding to this
ThreadInfo.
-
getThreadState
public Thread.State getThreadState()
Returns the thread state value of the thread represented by thisThreadInfo.- Returns:
- the thread state of the thread corresponding to this
ThreadInfo. - See Also:
Thread.getState()
-
getWaitedCount
public long getWaitedCount()
The number of times that the thread represented by thisThreadInfohas gone to the "wait" or "timed wait" state.- Returns:
- the number of times the corresponding thread has been in the "wait" or "timed wait" state.
-
getWaitedTime
public long getWaitedTime()
If thread contention monitoring is supported and enabled, returns the total amount of time that the thread represented by thisThreadInfohas spent waiting for notifications. The time is measured in milliseconds and will be measured over the time period since thread contention was most recently enabled.- Returns:
- if thread contention monitoring is currently enabled, the number
of milliseconds that the thread associated with this
ThreadInfohas spent waiting notifications. If thread contention monitoring is supported but currently disabled,-1. - Throws:
UnsupportedOperationException- if the virtual machine does not support thread contention monitoring.- See Also:
ThreadMXBean.isThreadContentionMonitoringSupported(),ThreadMXBean.isThreadContentionMonitoringEnabled()
-
isInNative
public boolean isInNative()
Returns abooleanindication of whether or not the thread represented by thisThreadInfois currently in a native method.- Returns:
- if the corresponding thread is executing a native method
then
true, otherwisefalse.
-
isSuspended
public boolean isSuspended()
Returns abooleanindication of whether or not the thread represented by thisThreadInfois currently suspended.- Returns:
- if the corresponding thread is suspended then
true, otherwisefalse.
-
getLockedMonitors
public MonitorInfo[] getLockedMonitors()
Returns an array ofMonitorInfoobjects, one for every monitor object locked by theThreadcorresponding to thisThreadInfowhen it was instantiated.- Returns:
- an array whose elements comprise of
MonitorInfoobjects - one for each object monitor locked by thisThreadInfoobject's corresponding thread. If no monitors are locked by the thread then the array will have a length of zero.
-
getLockedSynchronizers
public LockInfo[] getLockedSynchronizers()
Returns an array ofLockInfoobjects, each one containing information on an ownable synchronizer (a synchronizer that makes use of theAbstractOwnableSynchronizertype and which is completely owned by a single thread) locked by theThreadcorresponding to thisThreadInfowhen it was instantiated.- Returns:
- an array whose elements comprise of
LockInfoobjects - one for each ownable synchronizer locked by thisThreadInfoobject's corresponding thread. If no ownable synchronizer are locked by the thread then the array will have a length of zero.
-
from
public static ThreadInfo from(CompositeData cd)
Receives aCompositeDatarepresenting aThreadInfoobject and attempts to return the rootThreadInfoinstance.- Parameters:
cd- aCompositeDatathat represents aThreadInfo.- Returns:
- if
cdis non-null, returns a new instance ofThreadInfo. Ifcdisnull, returnsnull. - Throws:
IllegalArgumentException- if argumentcddoes not correspond to aThreadInfowith the following attributes: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)daemon(java.lang.Boolean)priority(java.lang.Integer)lockInfo(javax.management.openmbean.CompositeData) which holds the simple attributesclassName(java.lang.String),identityHashCode(java.lang.Integer). In the event that the inputCompositeDatadoes not hold alockInfoattribute, the value of thelockNameattribute is used for setting the returned object'sLockInfostate.lockName(java.lang.String)lockOwnerId(java.lang.Long)lockOwnerName(java.lang.String)stackTrace(javax.management.openmbean.CompositeData[])
stackTracearray must correspond to ajava.lang.StackTraceElementand have the following attributes :moduleName(java.lang.String)moduleVersion(java.lang.String)className(java.lang.String)methodName(java.lang.String)fileName(java.lang.String)lineNumber(java.lang.Integer)nativeMethod(java.lang.Boolean)
-
isDaemon
public boolean isDaemon()
Returns abooleanindication of whether or not the thread represented by thisThreadInfois currently a daemon thread.- Returns:
trueif this thread is a daemon thread, otherwisefalse.
-
getPriority
public int getPriority()
Returns the thread priority of the thread represented by thisThreadInfo.- Returns:
- The priority of the thread represented by this
ThreadInfo.
-
-