APIdia Launch Partner
Top Description Fields Constructors Methods
java.lang.management

public Class ThreadInfo

extends Object
Class Inheritance
Imports
java.lang.foreign.Linker, javax.management.openmbean.ArrayType, .CompositeData, sun.management.ManagementFactoryHelper, .ThreadInfoCompositeData

Thread information. ThreadInfo contains the information about a thread including:

General thread information

Execution information

Synchronization Statistics

This thread information class is designed for use in monitoring of the system, not for synchronization control.

MXBean Mapping

ThreadInfo is mapped to a CompositeData with attributes as specified in the from method.
Author
Mandy Chung
Since
1.5
See Also
ThreadMXBean#getThreadInfo, ThreadMXBean#dumpAllThreads

Field Summary

Modifier and TypeField and Description
private long
private long
private boolean
private static MonitorInfo[]
private static LockInfo[]
private boolean
private LockInfo
private MonitorInfo[]
private LockInfo[]
private String
private long
private String
private static final int
private static final StackTraceElement[]
private int
private StackTraceElement[]
private boolean
private long
private String
private Thread.State
private long
private long

Constructor Summary

AccessConstructor and Description
private
ThreadInfo(Thread
Thread
t
,
int
Thread state
state
,
Object
Object on which the thread is blocked
lockObj
,
Thread
the thread holding the lock
lockOwner
,
long
Number of times blocked to enter a lock
blockedCount
,
long
Approx time blocked to enter a lock
blockedTime
,
long
Number of times waited on a lock
waitedCount
,
long
Approx time waited on a lock
waitedTime
,
StackTraceElement[]
Thread stack trace
stackTrace
)

Constructor of ThreadInfo created by the JVM

private
ThreadInfo(Thread
Thread
t
,
int
Thread state
state
,
Object
Object on which the thread is blocked
lockObj
,
Thread
the thread holding the lock
lockOwner
,
long
Number of times blocked to enter a lock
blockedCount
,
long
Approx time blocked to enter a lock
blockedTime
,
long
Number of times waited on a lock
waitedCount
,
long
Approx time waited on a lock
waitedTime
,
StackTraceElement[]
Thread stack trace
stackTrace
,
Object[]
List of locked monitors
monitors
,
int[]
List of stack depths
stackDepths
,
Object[]
List of locked synchronizers
synchronizers
)

Constructor of ThreadInfo created by the JVM for ThreadMXBean#getThreadInfo(long[], boolean, boolean) and ThreadMXBean#dumpAllThreads

private

Method Summary

Modifier and TypeMethod and Description
public static ThreadInfo

Returns:

a ThreadInfo object represented by cd if cd is not null; null otherwise.
from
(CompositeData
CompositeData representing a ThreadInfo
cd
)

Returns a ThreadInfo object represented by the given CompositeData.

public long

Returns:

the total number of times that the thread entered the BLOCKED state.
getBlockedCount
()

Returns the total number of times that the thread associated with this ThreadInfo blocked to enter or reenter a monitor.

public long

Returns:

the approximate accumulated elapsed time in milliseconds that a thread entered the BLOCKED state; -1 if thread contention monitoring is disabled.
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.

public MonitorInfo[]

Returns:

an array of MonitorInfo objects representing the object monitors locked by the thread.
getLockedMonitors
()

Returns an array of MonitorInfo objects, each of which represents an object monitor currently locked by the thread associated with this ThreadInfo.

public LockInfo[]

Returns:

an array of LockInfo objects representing the ownable synchronizers locked by the thread.
getLockedSynchronizers
()

Returns an array of LockInfo objects, each of which represents an ownable synchronizer currently locked by the thread associated with this ThreadInfo.

public LockInfo

Returns:

LockInfo of an object for which the thread is blocked waiting if any; null otherwise.
getLockInfo
()

Returns the LockInfo of an object for which the thread associated with this ThreadInfo is blocked waiting.

public String

Returns:

the string representation of the object on which the thread is blocked if any; null otherwise.
getLockName
()

Returns the string representation of an object for which the thread associated with this ThreadInfo is blocked waiting.

public long

Returns:

the thread ID of the owner thread of the object this thread is blocked on; -1 if this thread is not blocked or if the object is not owned by any thread.
getLockOwnerId
()

Returns the ID of the thread which owns the object for which the thread associated with this ThreadInfo is blocked waiting.

public String

Returns:

the name of the thread that owns the object this thread is blocked on; null if this thread is not blocked or if the object is not owned by any thread.
getLockOwnerName
()

Returns the name of the thread which owns the object for which the thread associated with this ThreadInfo is blocked waiting.

public int

Returns:

The priority of the thread associated with this ThreadInfo.
getPriority
()

Returns the thread priority of the thread associated with this ThreadInfo.

public StackTraceElement[]

Returns:

an array of StackTraceElement objects of the thread.
getStackTrace
()

Returns the stack trace of the thread associated with this ThreadInfo.

public long

Returns:

the ID of the associated thread.
getThreadId
()

Returns the ID of the thread associated with this ThreadInfo.

public String

Returns:

the name of the associated thread.
getThreadName
()

Returns the name of the thread associated with this ThreadInfo.

public Thread.State

Returns:

Thread.State of the associated thread.
getThreadState
()

Returns the state of the thread associated with this ThreadInfo.

public long

Returns:

the total number of times that the thread was in the WAITING or TIMED_WAITING state.
getWaitedCount
()

Returns the total number of times that the thread associated with this ThreadInfo waited for notification.

public long

Returns:

the approximate accumulated elapsed time in milliseconds that a thread has been in the WAITING or TIMED_WAITING state; -1 if thread contention monitoring is disabled.
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.

private void
initialize(Thread
Thread
t
,
int
Thread state
state
,
Object
Object on which the thread is blocked
lockObj
,
Thread
the thread holding the lock
lockOwner
,
long
Number of times blocked to enter a lock
blockedCount
,
long
Approx time blocked to enter a lock
blockedTime
,
long
Number of times waited on a lock
waitedCount
,
long
Approx time waited on a lock
waitedTime
,
StackTraceElement[]
Thread stack trace
stackTrace
,
MonitorInfo[]
List of locked monitors
lockedMonitors
,
LockInfo[]
List of locked synchronizers
lockedSynchronizers
)

Initialize ThreadInfo object

public boolean

Returns:

true if the thread is a daemon thread, false otherwise.
isDaemon
()

Tests if the thread associated with this ThreadInfo is a daemon thread.

public boolean

Returns:

true if the thread is executing native code; false otherwise.
isInNative
()

Tests if the thread associated with this ThreadInfo is executing native code.

public boolean

Returns:

true if the thread is suspended; false otherwise.
isSuspended
()

Tests if the thread associated with this ThreadInfo is suspended.

public String

Returns:

a string representation of this thread info.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this thread info.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

blockedCountback to summary
private long blockedCount
blockedTimeback to summary
private long blockedTime
daemonback to summary
private boolean daemon
EMPTY_MONITORSback to summary
private static MonitorInfo[] EMPTY_MONITORS
EMPTY_SYNCSback to summary
private static LockInfo[] EMPTY_SYNCS
inNativeback to summary
private boolean inNative
lockback to summary
private LockInfo lock
lockedMonitorsback to summary
private MonitorInfo[] lockedMonitors
lockedSynchronizersback to summary
private LockInfo[] lockedSynchronizers
lockNameback to summary
private String lockName
lockOwnerIdback to summary
private long lockOwnerId
lockOwnerNameback to summary
private String lockOwnerName
MAX_FRAMESback to summary
private static final int MAX_FRAMES
NO_STACK_TRACEback to summary
private static final StackTraceElement[] NO_STACK_TRACE
priorityback to summary
private int priority
stackTraceback to summary
private StackTraceElement[] stackTrace
suspendedback to summary
private boolean suspended
threadIdback to summary
private long threadId
threadNameback to summary
private String threadName
threadStateback to summary
private Thread.State threadState
waitedCountback to summary
private long waitedCount
waitedTimeback to summary
private long waitedTime

Constructor Detail

ThreadInfoback to summary
private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner, long blockedCount, long blockedTime, long waitedCount, long waitedTime, StackTraceElement[] stackTrace)

Constructor of ThreadInfo created by the JVM

Parameters
t:Thread

Thread

state:int

Thread state

lockObj:Object

Object on which the thread is blocked

lockOwner:Thread

the thread holding the lock

blockedCount:long

Number of times blocked to enter a lock

blockedTime:long

Approx time blocked to enter a lock

waitedCount:long

Number of times waited on a lock

waitedTime:long

Approx time waited on a lock

stackTrace:StackTraceElement[]

Thread stack trace

ThreadInfoback to summary
private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner, long blockedCount, long blockedTime, long waitedCount, long waitedTime, StackTraceElement[] stackTrace, Object[] monitors, int[] stackDepths, Object[] synchronizers)

Constructor of ThreadInfo created by the JVM for ThreadMXBean#getThreadInfo(long[], boolean, boolean) and ThreadMXBean#dumpAllThreads

Parameters
t:Thread

Thread

state:int

Thread state

lockObj:Object

Object on which the thread is blocked

lockOwner:Thread

the thread holding the lock

blockedCount:long

Number of times blocked to enter a lock

blockedTime:long

Approx time blocked to enter a lock

waitedCount:long

Number of times waited on a lock

waitedTime:long

Approx time waited on a lock

stackTrace:StackTraceElement[]

Thread stack trace

monitors:Object[]

List of locked monitors

stackDepths:int[]

List of stack depths

synchronizers:Object[]

List of locked synchronizers

ThreadInfoback to summary
private ThreadInfo(CompositeData cd)

Method Detail

fromback to summary
public static ThreadInfo from(CompositeData cd)

Returns a 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.

The attributes and their types for ThreadInfo's composite data
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 method.

If the given CompositeData does not contain this attribute, the LockInfo object will be constructed from the value of the lockName attribute.

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 CompositeData does not contain this attribute, this attribute will be set to an empty array.

6
lockedSynchronizers javax.management.openmbean.CompositeData[] whose element type is the mapped type for LockInfo as specified in the LockInfo#from method.

If the given CompositeData does not contain this attribute, this attribute will be set to an empty array.

6
daemon java.lang.Boolean

If the given CompositeData does not contain this attribute, this attribute will be set to false.

9
priority java.lang.Integer

If the given CompositeData does not contain this attribute, This attribute will be set to Thread#NORM_PRIORITY.

9
A CompositeData representing StackTraceElement of version N must contain all of the attributes defined in version ≤ N unless specified otherwise.
The attributes and their types for StackTraceElement's composite data
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
Parameters
cd:CompositeData

CompositeData representing a ThreadInfo

Returns:ThreadInfo

a ThreadInfo object represented by cd if cd is not null; null otherwise.

Exceptions
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.
getBlockedCountback to summary
public long getBlockedCount()

Returns the total number of times that the thread associated with this ThreadInfo blocked to enter or reenter a monitor. I.e. the number of times a thread has been in the BLOCKED state.

Returns:long

the total number of times that the thread entered the BLOCKED state.

getBlockedTimeback to summary
public 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. 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.

Returns:long

the approximate accumulated elapsed time in milliseconds that a thread entered the BLOCKED state; -1 if thread contention monitoring is disabled.

Exceptions
UnsupportedOperationException:
if the Java virtual machine does not support this operation.
See Also
ThreadMXBean#isThreadContentionMonitoringSupported, ThreadMXBean#setThreadContentionMonitoringEnabled
getLockedMonitorsback to summary
public MonitorInfo[] getLockedMonitors()

Returns an array of 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.

Returns:MonitorInfo[]

an array of MonitorInfo objects representing the object monitors locked by the thread.

Since
1.6
getLockedSynchronizersback to summary
public LockInfo[] getLockedSynchronizers()

Returns an array of 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.

Returns:LockInfo[]

an array of LockInfo objects representing the ownable synchronizers locked by the thread.

Since
1.6
getLockInfoback to summary
public LockInfo getLockInfo()

Returns the 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:

This method returns null if the thread is not in any of the above conditions.

Returns:LockInfo

LockInfo of an object for which the thread is blocked waiting if any; null otherwise.

Since
1.6
getLockNameback to summary
public String getLockName()

Returns the 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.

Returns:String

the string representation of the object on which the thread is blocked if any; null otherwise.

See Also
getLockInfo
getLockOwnerIdback to summary
public long getLockOwnerId()

Returns the ID of the thread which owns the object for which the thread associated with this 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.

Returns:long

the thread ID of the owner thread of the object this thread is blocked on; -1 if this thread is not blocked or if the object is not owned by any thread.

See Also
getLockInfo
getLockOwnerNameback to summary
public String getLockOwnerName()

Returns the name of the thread which owns the object for which the thread associated with this 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.

Returns:String

the name of the thread that owns the object this thread is blocked on; null if this thread is not blocked or if the object is not owned by any thread.

See Also
getLockInfo
getPriorityback to summary
public int getPriority()

Returns the thread priority of the thread associated with this ThreadInfo.

Returns:int

The priority of the thread associated with this ThreadInfo.

Since
9
getStackTraceback to summary
public StackTraceElement[] getStackTrace()

Returns the stack trace of the thread associated with this 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.

Returns:StackTraceElement[]

an array of StackTraceElement objects of the thread.

getThreadIdback to summary
public long getThreadId()

Returns the ID of the thread associated with this ThreadInfo.

Returns:long

the ID of the associated thread.

getThreadNameback to summary
public String getThreadName()

Returns the name of the thread associated with this ThreadInfo.

Returns:String

the name of the associated thread.

getThreadStateback to summary
public Thread.State getThreadState()

Returns the state of the thread associated with this ThreadInfo.

Returns:Thread.State

Thread.State of the associated thread.

getWaitedCountback to summary
public long getWaitedCount()

Returns the total number of times that the thread associated with this ThreadInfo waited for notification. I.e. the number of times that a thread has been in the WAITING or TIMED_WAITING state.

Returns:long

the total number of times that the thread was in the WAITING or TIMED_WAITING state.

getWaitedTimeback to summary
public 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. 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.

Returns:long

the approximate accumulated elapsed time in milliseconds that a thread has been in the WAITING or TIMED_WAITING state; -1 if thread contention monitoring is disabled.

Exceptions
UnsupportedOperationException:
if the Java virtual machine does not support this operation.
See Also
ThreadMXBean#isThreadContentionMonitoringSupported, ThreadMXBean#setThreadContentionMonitoringEnabled
initializeback to summary
private void initialize(Thread t, int state, Object lockObj, Thread lockOwner, long blockedCount, long blockedTime, long waitedCount, long waitedTime, StackTraceElement[] stackTrace, MonitorInfo[] lockedMonitors, LockInfo[] lockedSynchronizers)

Initialize ThreadInfo object

Parameters
t:Thread

Thread

state:int

Thread state

lockObj:Object

Object on which the thread is blocked

lockOwner:Thread

the thread holding the lock

blockedCount:long

Number of times blocked to enter a lock

blockedTime:long

Approx time blocked to enter a lock

waitedCount:long

Number of times waited on a lock

waitedTime:long

Approx time waited on a lock

stackTrace:StackTraceElement[]

Thread stack trace

lockedMonitors:MonitorInfo[]

List of locked monitors

lockedSynchronizers:LockInfo[]

List of locked synchronizers

isDaemonback to summary
public boolean isDaemon()

Tests if the thread associated with this ThreadInfo is a daemon thread.

Returns:boolean

true if the thread is a daemon thread, false otherwise.

Since
9
See Also
Thread#isDaemon
isInNativeback to summary
public boolean isInNative()

Tests if the thread associated with this ThreadInfo is executing native code.

A thread is considered to be executing native code when it is executing a native method, executing native code invoked using a method handle obtained from the native linker, or is attached to the VM with the Java Native Interface with no Java frames on its stack.

Native code does not include Java virtual machine support code, compiled code generated by the Java virtual machine, or special cases such as a thread blocked on a JVM TI raw monitor.

Returns:boolean

true if the thread is executing native code; false otherwise.

isSuspendedback to summary
public boolean isSuspended()

Tests if the thread associated with this ThreadInfo is suspended.

Returns:boolean

true if the thread is suspended; false otherwise.

External Specification
JVM Tool Interface
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this thread info. The format of this string depends on the implementation. The returned string will typically include the thread name, the thread ID, its state, and a stack trace if any.

Returns:String

a string representation of this thread info.