java.lang.management

Class ThreadInfo


public class ThreadInfo
extends Object

A class which maintains information about a particular thread. This information includes:
  • Execution Information:
  • Synchronization Statistics
  • Since:
    1.5
    See Also:
    ThreadMXBean.isThreadContentionMonitoringSupported()

    Method Summary

    static ThreadInfo
    from(CompositeData data)
    Returns a ThreadInfo instance using the values given in the supplied CompositeData object.
    long
    getBlockedCount()
    Returns the number of times this thread has been in the Thread.State state.
    long
    getBlockedTime()
    Returns the accumulated number of milliseconds this thread has been in the Thread.State state since thread contention monitoring was last enabled.
    LockInfo
    getLockInfo()
    Returns a LockInfo object representing the lock on which this thread is blocked.
    String
    getLockName()
    Returns a String representation of the 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.
    MonitorInfo[]
    getLockedMonitors()
    Returns an array of MonitorInfo objects representing information on the locks on object monitors held by the thread.
    LockInfo[]
    getLockedSynchronizers()
    Returns an array of LockInfo objects representing information on the locks on ownable synchronizers held by the thread.
    StackTraceElement[]
    getStackTrace()
    Returns the stack trace of this thread to the depth specified on creation of this ThreadInfo object.
    long
    getThreadId()
    Returns the identifier of the thread associated with this instance of ThreadInfo.
    String
    getThreadName()
    Returns the name of the thread associated with this instance of ThreadInfo.
    Thread.State
    getThreadState()
    Returns the state of the thread associated with this instance of ThreadInfo.
    long
    getWaitedCount()
    Returns the number of times this thread has been in the Thread.State or Thread.State state.
    long
    getWaitedTime()
    Returns the accumulated number of milliseconds this thread has been in the Thread.State or Thread.State 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 Thread.suspend().
    String
    toString()
    Returns a String representation of this ThreadInfo object.

    Methods inherited from class java.lang.Object

    clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

    Method Details

    from

    public static ThreadInfo from(CompositeData data)
    Returns a ThreadInfo instance using the values given in the supplied CompositeData object. The composite data instance should contain the following attributes with the specified types:
    NameType
    threadIdjava.lang.Long
    threadNamejava.lang.String
    threadStatejava.lang.String
    suspendedjava.lang.Boolean
    inNativejava.lang.Boolean
    blockedCountjava.lang.Long
    blockedTimejava.lang.Long
    waitedCountjava.lang.Long
    waitedTimejava.lang.Long
    lockNamejava.lang.String
    lockOwnerIdjava.lang.Long
    lockOwnerNamejava.lang.String
    stackTracejavax.management.openmbean.CompositeData[]

    The stack trace is further described as:

    NameType
    classNamejava.lang.String
    methodNamejava.lang.String
    fileNamejava.lang.String
    lineNumberjava.lang.Integer
    nativeMethodjava.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.

    getBlockedCount

    public long getBlockedCount()
    Returns the number of times this thread has been in the Thread.State state. 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 Object.wait().
    Returns:
    the number of times this thread has been blocked.

    getBlockedTime

    public long getBlockedTime()
    Returns the accumulated number of milliseconds this thread has been in the Thread.State 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 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.

    getLockInfo

    public LockInfo getLockInfo()
    Returns a LockInfo object representing the lock on which this thread is blocked. If the thread is not blocked, this method returns null.

    The thread may be blocked due to one of three reasons:

    1. The thread is in the BLOCKED state waiting to acquire an object monitor in order to enter a synchronized method or block.
    2. The thread is in the WAITING or TIMED_WAITING state due to a call to Object.wait().
    3. The thread is in the WAITING or TIMED_WAITING state due to a call to java.util.concurrent.locks.LockSupport.park(). The lock is the return value of java.util.concurrent.locks.LockSupport.getBlocker().
    Returns:
    a LockInfo object representing the lock on which the thread is blocked, or null if the thread isn't blocked.
    Since:
    1.6
    See Also:
    getLockName()

    getLockName

    public String getLockName()
    Returns a String representation of the lock on which this thread is blocked. If the thread is not blocked, this method returns null.

    The returned 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. The value is the same as would be returned by getLockInfo().toString()

    Returns:
    a string representing the lock on which this thread is blocked, or null if the thread is not blocked.

    getLockOwnerId

    public long getLockOwnerId()
    Returns the identifier of the thread which owns the monitor lock this thread is waiting for. -1 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 -1 if the thread is not blocked or the lock is not held by another thread.

    getLockOwnerName

    public String getLockOwnerName()
    Returns the name of the thread which owns the monitor lock this thread is waiting for. 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.

    getLockedMonitors

    public MonitorInfo[] getLockedMonitors()
    Returns an array of MonitorInfo objects representing information on the locks on object monitors held by the thread. If no locks are held, or such information was not requested on creating this ThreadInfo object, a zero-length array will be returned.
    Returns:
    information on object monitors locked by this thread.

    getLockedSynchronizers

    public LockInfo[] getLockedSynchronizers()
    Returns an array of LockInfo objects representing information on the locks on ownable synchronizers held by the thread. If no locks are held, or such information was not requested on creating this ThreadInfo object, a zero-length array will be returned.
    Returns:
    information on ownable synchronizers locked by this thread.

    getStackTrace

    public StackTraceElement[] getStackTrace()
    Returns the stack trace of this thread to the depth specified on creation of this 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 StackTraceElements representing the trace of this thread.

    getThreadId

    public long getThreadId()
    Returns the identifier of the thread associated with this instance of ThreadInfo.
    Returns:
    the thread's identifier.

    getThreadName

    public String getThreadName()
    Returns the name of the thread associated with this instance of ThreadInfo.
    Returns:
    the thread's name.

    getThreadState

    public Thread.State getThreadState()
    Returns the state of the thread associated with this instance of ThreadInfo.
    Returns:
    the thread's state.

    getWaitedCount

    public long getWaitedCount()
    Returns the number of times this thread has been in the Thread.State or Thread.State state. A thread enters one of these states when it is waiting due to a call to java.lang.Object.wait(), java.lang.Object.join() or java.lang.concurrent.locks.LockSupport.park(), either with an infinite or timed delay, respectively.
    Returns:
    the number of times this thread has been waiting.

    getWaitedTime

    public long getWaitedTime()
    Returns the accumulated number of milliseconds this thread has been in the Thread.State or Thread.State state, since thread contention monitoring was last enabled. A thread enters one of these states when it is waiting due to a call to java.lang.Object.wait(), java.lang.Object.join() or 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.

    isInNative

    public boolean isInNative()
    Returns true if the thread is in a native method. This excludes native code which forms part of the virtual machine itself, or which results from Just-In-Time compilation.
    Returns:
    true if the thread is in a native method, false otherwise.

    isSuspended

    public boolean isSuspended()
    Returns true if the thread has been suspended using Thread.suspend().
    Returns:
    true if the thread is suspended, false otherwise.

    toString

    public String toString()
    Returns a String representation of this ThreadInfo object. This takes the form 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).
    Overrides:
    toString in interface Object
    Returns:
    the string specified above.

    ThreadInfo.java - Information on a thread Copyright (C) 2006 Free Software Foundation This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.