Class ThreadInfo

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

    Modifier and Type
    Method
    Description
    static ThreadInfo
    Receives a CompositeData representing a ThreadInfo object and attempts to return the root ThreadInfo instance.
    long
    Returns the number of times that the thread represented by this ThreadInfo has been blocked on any monitor objects.
    long
    If thread contention monitoring is supported and enabled, returns the total amount of time that the thread represented by this ThreadInfo has spent blocked on any monitor objects.
    Returns an array of MonitorInfo objects, one for every monitor object locked by the Thread corresponding to this ThreadInfo when it was instantiated.
    Returns an array of LockInfo objects, each one containing information on an ownable synchronizer (a synchronizer that makes use of the AbstractOwnableSynchronizer type and which is completely owned by a single thread) locked by the Thread corresponding to this ThreadInfo when it was instantiated.
    If the thread corresponding to this ThreadInfo is blocked then this method returns a LockInfo object that contains details of the associated lock object.
    If the thread represented by this ThreadInfo is currently blocked on or waiting on a monitor object, returns a string representation of that monitor object.
    long
    If the thread represented by this ThreadInfo is 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 this ThreadInfo is currently blocked on or waiting on a monitor object, returns the name of the thread which owns the monitor.
    int
    Returns the thread priority of the thread represented by this ThreadInfo.
    If available, returns the stack trace for the thread represented by this ThreadInfo instance.
    long
    Returns the thread identifier of the thread represented by this ThreadInfo.
    Returns the name of the thread represented by this ThreadInfo.
    Returns the thread state value of the thread represented by this ThreadInfo.
    long
    The number of times that the thread represented by this ThreadInfo has gone to the "wait" or "timed wait" state.
    long
    If thread contention monitoring is supported and enabled, returns the total amount of time that the thread represented by this ThreadInfo has spent waiting for notifications.
    boolean
    Returns a boolean indication of whether or not the thread represented by this ThreadInfo is currently a daemon thread.
    boolean
    Returns a boolean indication of whether or not the thread represented by this ThreadInfo is currently in a native method.
    boolean
    Returns a boolean indication of whether or not the thread represented by this ThreadInfo is currently suspended.
    Answers a string containing a concise, human-readable description of the receiver.

    Methods declared in class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • getBlockedCount

      public long getBlockedCount()
      Returns the number of times that the thread represented by this ThreadInfo has 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 this ThreadInfo has 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 ThreadInfo has 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

      public String getLockName()
      If the thread represented by this ThreadInfo is 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:

      • monitor class 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 this ThreadInfo is 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 ThreadInfo is blocked or waiting on. If this ThreadInfo'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 this ThreadInfo is 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 ThreadInfo is blocked or waiting on. If this ThreadInfo's associated thread is currently not blocked or waiting, or there is no other thread holding the monitor, returns a null reference.
    • getLockInfo

      public LockInfo getLockInfo()
      If the thread corresponding to this ThreadInfo is blocked then this method returns a LockInfo object that contains details of the associated lock object.
      Returns:
      a LockInfo object if this ThreadInfo's thread is currently blocked, else null.
    • getStackTrace

      public StackTraceElement[] getStackTrace()
      If available, returns the stack trace for the thread represented by this ThreadInfo instance. The stack trace is returned in an array of StackTraceElement objects 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 ThreadInfo was created without any stack trace information (e.g. by a call to ThreadMXBean.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 this ThreadInfo.
      Returns:
      the identifier of the thread corresponding to this ThreadInfo.
    • getThreadName

      public String getThreadName()
      Returns the name of the thread represented by this ThreadInfo.
      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 this ThreadInfo.
      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 this ThreadInfo has 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 this ThreadInfo has 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 ThreadInfo has 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 a boolean indication of whether or not the thread represented by this ThreadInfo is currently in a native method.
      Returns:
      if the corresponding thread is executing a native method then true, otherwise false.
    • isSuspended

      public boolean isSuspended()
      Returns a boolean indication of whether or not the thread represented by this ThreadInfo is currently suspended.
      Returns:
      if the corresponding thread is suspended then true, otherwise false.
    • getLockedMonitors

      public MonitorInfo[] getLockedMonitors()
      Returns an array of MonitorInfo objects, one for every monitor object locked by the Thread corresponding to this ThreadInfo when it was instantiated.
      Returns:
      an array whose elements comprise of MonitorInfo objects - one for each object monitor locked by this ThreadInfo object'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 of LockInfo objects, each one containing information on an ownable synchronizer (a synchronizer that makes use of the AbstractOwnableSynchronizer type and which is completely owned by a single thread) locked by the Thread corresponding to this ThreadInfo when it was instantiated.
      Returns:
      an array whose elements comprise of LockInfo objects - one for each ownable synchronizer locked by this ThreadInfo object'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 a CompositeData representing a ThreadInfo object and attempts to return the root ThreadInfo instance.
      Parameters:
      cd - a CompositeData that represents a ThreadInfo.
      Returns:
      if cd is non- null, returns a new instance of ThreadInfo. If cd is null, returns null.
      Throws:
      IllegalArgumentException - if argument cd does not correspond to a ThreadInfo with 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 attributes className(java.lang.String), identityHashCode(java.lang.Integer). In the event that the input CompositeData does not hold a lockInfo attribute, the value of the lockName attribute is used for setting the returned object's LockInfo state.
      • lockName (java.lang.String)
      • lockOwnerId (java.lang.Long)
      • lockOwnerName (java.lang.String)
      • stackTrace (javax.management.openmbean.CompositeData[])
      Each element of the stackTrace array must correspond to a java.lang.StackTraceElement and 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 a boolean indication of whether or not the thread represented by this ThreadInfo is currently a daemon thread.
      Returns:
      true if this thread is a daemon thread, otherwise false .
    • getPriority

      public int getPriority()
      Returns the thread priority of the thread represented by this ThreadInfo.
      Returns:
      The priority of the thread represented by this ThreadInfo.
    • toString

      public String toString()
      Description copied from class: Object
      Answers a string containing a concise, human-readable description of the receiver.
      Overrides:
      toString in class Object
      Returns:
      a text description of this thread.