Class ThreadInfo
java.lang.Object
java.lang.management.ThreadInfo
Information about a snapshot of the state of a thread.
- Since:
- 1.5
-
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadInfofrom(CompositeData cd) Receives aCompositeDatarepresenting aThreadInfoobject and attempts to return the rootThreadInfoinstance.longReturns the number of times that the thread represented by thisThreadInfohas been blocked on any monitor objects.longIf 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.Returns an array ofMonitorInfoobjects, one for every monitor object locked by theThreadcorresponding to thisThreadInfowhen it was instantiated.LockInfo[]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.If the thread corresponding to thisThreadInfois blocked then this method returns aLockInfoobject that contains details of the associated lock object.If the thread represented by thisThreadInfois currently blocked on or waiting on a monitor object, returns a string representation of that monitor object.longIf 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.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.intReturns the thread priority of the thread represented by thisThreadInfo.If available, returns the stack trace for the thread represented by thisThreadInfoinstance.longReturns the thread identifier of the thread represented by thisThreadInfo.Returns the name of the thread represented by thisThreadInfo.Returns the thread state value of the thread represented by thisThreadInfo.longThe number of times that the thread represented by thisThreadInfohas gone to the "wait" or "timed wait" state.longIf 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.booleanReturns abooleanindication of whether or not the thread represented by thisThreadInfois currently in a native method.booleanReturns abooleanindication of whether or not the thread represented by thisThreadInfois currently suspended.toString()Answers a string containing a concise, human-readable description of the receiver.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Method Details
-
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:
-
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:
-
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
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
-
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
Returns the name of the thread represented by thisThreadInfo.- Returns:
- the name of the thread corresponding to this
ThreadInfo.
-
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:
-
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:
-
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
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
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
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.
-
toString
-