com.ibm.lang.management

Class ThreadMXBeanImpl

  1. java.lang.Object
  2. extended bycom.ibm.lang.management.DynamicMXBeanImpl
  3. extended bycom.ibm.lang.management.ThreadMXBeanImpl
All implemented interfaces:
java.lang.management.ThreadMXBean, javax.management.DynamicMBean

  1. public final class ThreadMXBeanImpl
  2. extends DynamicMXBeanImpl
  3. implements java.lang.management.ThreadMXBean
Runtime type for ThreadMXBean
Since:
1.5

Field Summary

Fields inherited from class com.ibm.lang.management.DynamicMXBeanImpl
info

Method Summary

Modifier and Type Method and Description
  1. java.lang.management.ThreadInfo[]
dumpAllThreads(boolean lockedMonitors,boolean lockedSynchronizers)
  1. long[]
findDeadlockedThreads()
  1. long[]
findMonitorDeadlockedThreads()
  1. long[]
getAllThreadIds()
  1. long
getCurrentThreadCpuTime()
  1. long
getCurrentThreadUserTime()
  1. int
getDaemonThreadCount()
  1. int
getPeakThreadCount()
  1. int
getThreadCount()
  1. long
getThreadCpuTime(long id)
  1. java.lang.management.ThreadInfo
getThreadInfo(long id)
  1. java.lang.management.ThreadInfo[]
getThreadInfo(long[] ids)
  1. java.lang.management.ThreadInfo[]
getThreadInfo(long[] ids,boolean lockedMonitors,boolean lockedSynchronizers)
Get together information for threads and create instances of the ThreadInfo class.
  1. java.lang.management.ThreadInfo[]
getThreadInfo(long[] ids,int maxDepth)
  1. java.lang.management.ThreadInfo
getThreadInfo(long id,int maxDepth)
  1. long
getThreadUserTime(long id)
  1. long
getTotalStartedThreadCount()
  1. boolean
isCurrentThreadCpuTimeSupported()
  1. boolean
isObjectMonitorUsageSupported()
  1. boolean
isSynchronizerUsageSupported()
  1. boolean
isThreadContentionMonitoringEnabled()
  1. boolean
isThreadContentionMonitoringSupported()
  1. boolean
isThreadCpuTimeEnabled()
  1. boolean
isThreadCpuTimeSupported()
  1. void
resetPeakThreadCount()
  1. void
setThreadContentionMonitoringEnabled(boolean enable)
  1. void
setThreadCpuTimeEnabled(boolean enable)
Methods inherited from class com.ibm.lang.management.DynamicMXBeanImpl
getAttribute, getAttributes, getMBeanInfo, getPresentAttribute, getPresentOperation, initMBeanInfo, invoke, setAttribute, setAttributes, setMBeanInfo
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail

findMonitorDeadlockedThreads

  1. public long[] findMonitorDeadlockedThreads( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns the thread identifiers of every thread in this virtual machine that is currently blocked in a deadlock situation over a monitor object. A thread is considered to be deadlocked if it is blocked waiting to run and owns an object monitor that is sought by another blocked thread. Two or more threads can be in a deadlock cycle. To determine the threads currently deadlocked by object monitors and ownable synchronizers use the ThreadMXBean.findDeadlockedThreads() method.

It is recommended that this method be used solely for problem determination analysis and not as a means of managing thread synchronization in a virtual machine. This is because the method may be very expensive to run.

Specified by:
findMonitorDeadlockedThreads in interface java.lang.management.ThreadMXBean
Returns:
an array of the identifiers of every thread in the virtual machine that has been detected as currently being in a deadlock situation over an object monitor. May be null if there are currently no threads in that category.

getAllThreadIds

  1. public long[] getAllThreadIds()

Description copied from interface: java.lang.management.ThreadMXBean

Returns an array of the identifiers of all of the threads that are alive in the current virtual machine. When processing the return from this method it should not be assumed that each identified thread is still alive.
Specified by:
getAllThreadIds in interface java.lang.management.ThreadMXBean
Returns:
the identifiers of all of the threads currently alive in the virtual machine.

getCurrentThreadCpuTime

  1. public long getCurrentThreadCpuTime( )

Description copied from interface: java.lang.management.ThreadMXBean

If supported by the virtual machine, returns the total CPU usage time for the currently running thread. The returned time will have nanosecond precision but may not have nanosecond accuracy.

Method ThreadMXBean.isCurrentThreadCpuTimeSupported()may be used to determine if current thread CPU timing is supported on the virtual machine. On virtual machines where current thread CPU timing is supported, the method ThreadMXBean.isThreadCpuTimeEnabled()may be used to determine if thread CPU timing is actually enabled.

The return value is identical to that which would be obtained by calling ThreadMXBean.getThreadCpuTime(long)with an argument Thread.currentThread().getId()).

Specified by:
getCurrentThreadCpuTime in interface java.lang.management.ThreadMXBean
Returns:
on virtual machines where current thread CPU timing is supported and thread CPU timing is enabled, the number of nanoseconds CPU usage by the current thread. On virtual machines where current thread CPU timing is supported but thread CPU timing is not enabled, -1.

getCurrentThreadUserTime

  1. public long getCurrentThreadUserTime( )

Description copied from interface: java.lang.management.ThreadMXBean

If supported by the virtual machine, returns the total CPU usage time for the current thread running in user mode. The returned time will have nanosecond precision but may not have nanosecond accuracy.

Method ThreadMXBean.isCurrentThreadCpuTimeSupported()may be used to determine if current thread CPU timing is supported on the virtual machine. On virtual machines where current thread CPU timing is supported, the method ThreadMXBean.isThreadCpuTimeEnabled()may be used to determine if thread CPU timing is actually enabled.

The return value is identical to that which would be obtained by calling ThreadMXBean.getThreadUserTime(long)with an argument Thread.currentThread().getId()).

Specified by:
getCurrentThreadUserTime in interface java.lang.management.ThreadMXBean
Returns:
on virtual machines where current thread CPU timing is supported and thread CPU timing is enabled, the number of nanoseconds CPU time used by the current thread running in user mode. On virtual machines where current thread CPU timing is supported but thread CPU timing is not enabled, -1.

getDaemonThreadCount

  1. public int getDaemonThreadCount( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns the number of daemon threads currently alive in the virtual machine.
Specified by:
getDaemonThreadCount in interface java.lang.management.ThreadMXBean
Returns:
the number of currently alive daemon threads.

getPeakThreadCount

  1. public int getPeakThreadCount()

Description copied from interface: java.lang.management.ThreadMXBean

Returns the peak number of threads that have ever been alive in the virtual machine at any one instant since either the virtual machine start-up or the peak was reset.
Specified by:
getPeakThreadCount in interface java.lang.management.ThreadMXBean
Returns:
the peak number of live threads
See Also:
ThreadMXBean.resetPeakThreadCount()

getThreadCount

  1. public int getThreadCount()

Description copied from interface: java.lang.management.ThreadMXBean

Returns the number of threads currently alive in the virtual machine. This includes both daemon threads and non-daemon threads.
Specified by:
getThreadCount in interface java.lang.management.ThreadMXBean
Returns:
the number of currently alive threads.

getThreadCpuTime

  1. public long getThreadCpuTime(long id)

Description copied from interface: java.lang.management.ThreadMXBean

If supported by the virtual machine, returns the total CPU usage time for the thread with the specified identifier. The returned time will have nanosecond precision but may not have nanosecond accuracy.

Method ThreadMXBean.isThreadCpuTimeSupported()may be used to determine if the CPU timing of threads is supported on the virtual machine. On virtual machines where current thread CPU timing is supported, the method ThreadMXBean.isThreadCpuTimeEnabled()may be used to determine if thread CPU timing is actually enabled.

Specified by:
getThreadCpuTime in interface java.lang.management.ThreadMXBean
Parameters:
id - the identifier for a thread. Must be a positive number greater than zero.
Returns:
on virtual machines where thread CPU timing is supported and enabled, and there is a living thread with identifier id, the number of nanoseconds CPU time used by the thread. On virtual machines where thread CPU timing is supported but not enabled, or where there is no living thread with identifier id present in the virtual machine, a value of -1 is returned.
See Also:
ThreadMXBean.isThreadCpuTimeSupported(), ThreadMXBean.isThreadCpuTimeEnabled()

getThreadInfo

  1. public java.lang.management.ThreadInfo getThreadInfo( long id)

Description copied from interface: java.lang.management.ThreadMXBean

Returns a ThreadInfoobject for the thread with the specified identifier. The returned object will not have a stack trace so that a call to its getStackTrace() method will result in an empty StackTraceElement array. Similarly, the returned object will hold no details of locked synchronizers or locked object monitors for the specified thread; calls to getLockedMonitors() and getLockedSynchronizers will both return array values.
Specified by:
getThreadInfo in interface java.lang.management.ThreadMXBean
Parameters:
id - the identifier for a thread. Must be a positive number greater than zero.
Returns:
if the supplied id maps to a living thread in the virtual machine (i.e. a started thread which has not yet died), this method returns a ThreadInfoobject corresponding to that thread. Otherwise, returns null.

getThreadInfo

  1. public java.lang.management.ThreadInfo[] getThreadInfo( long[] ids)

Description copied from interface: java.lang.management.ThreadMXBean

Returns an array of ThreadInfoobjects ; one for each of the threads specified in the input array of identifiers. None of the objects in the return array will have a stack trace so that a call to its getStackTrace() method will result in an empty StackTraceElement array. Similarly, the returned object will hold no details of locked synchronizers or locked object monitors for the specified thread; calls to getLockedMonitors() and getLockedSynchronizers will both return array values.
Specified by:
getThreadInfo in interface java.lang.management.ThreadMXBean
Parameters:
ids - an array of thread identifiers. Each one must be a positive number greater than zero.
Returns:
an array of ThreadInfoobjects with each entry corresponding to one of the threads specified in the input array of identifiers. The return array will therefore have an identical number of elements to the input ids array. If an entry in the ids array is invalid (there is no living thread with the supplied identifier in the virtual machine) then the corresponding entry in the return array will be a null.

getThreadInfo

  1. public java.lang.management.ThreadInfo[] getThreadInfo( long[] ids,
  2. int maxDepth)

Description copied from interface: java.lang.management.ThreadMXBean

Returns an array of ThreadInfoobjects ; one for each of the threads specified in the ids argument. The stack trace information in the returned objects will depend on the value of the maxDepth argument which specifies the maximum number of StackTraceElementinstances to try and include. A subsequent call to any of the returned objects' getStackTrace() method should result in a StackTraceElementarray of up to maxDepth elements. A maxDepth value of Integer.MAX_VALUE will attempt to obtain all of the stack trace information for each specified thread while a maxDepth value of zero will yield none.

The returned object will hold no details of locked synchronizers or locked object monitors for the specified thread; calls to getLockedMonitors() and getLockedSynchronizers will both return array values.

Specified by:
getThreadInfo in interface java.lang.management.ThreadMXBean
Parameters:
ids - an array of thread identifiers. Each must be a positive number greater than zero.
maxDepth - the maximum number of stack trace entries to be included in each of the returned ThreadInfo objects. Supplying Integer.MAX_VALUE attempts to obtain all of the stack traces. Only a positive value is expected.
Returns:
an array of ThreadInfo objects. The size of the array will be identical to that of the ids argument. Null elements will be placed in the array if the corresponding thread identifier in ids does not resolve to a living thread in the virtual machine (i.e. a started thread which has not yet died).

getThreadInfo

  1. public java.lang.management.ThreadInfo[] getThreadInfo( long[] ids,
  2. boolean lockedMonitors,
  3. boolean lockedSynchronizers)
Get together information for threads and create instances of the ThreadInfo class.

Assumes that caller has already carried out error checking on the id and maxDepth arguments.

Specified by:
getThreadInfo in interface java.lang.management.ThreadMXBean
Parameters:
ids - thread ids
lockedMonitors - if true attempt to set the returned ThreadInfo with details of object monitors locked by the specified thread
lockedSynchronizers - if true attempt to set the returned ThreadInfo with details of ownable synchronizers locked by the specified thread
Returns:
information for threads

getThreadInfo

  1. public java.lang.management.ThreadInfo getThreadInfo( long id,
  2. int maxDepth)

Description copied from interface: java.lang.management.ThreadMXBean

Returns a ThreadInfoobject for the thread with the specified identifier. The stack trace information in the returned object will depend on the value of the maxDepth argument which specifies the maximum number of StackTraceElementinstances to include. A subsequent call to the returned object's getStackTrace() method should then result in a StackTraceElementarray of up to maxDepth elements. A maxDepth value of Integer.MAX_VALUE will obtain all of the stack trace information for the thread while a maxDepth value of zero will yield none.

It is possible that the virtual machine may be unable to supply any stack trace information for the specified thread. In that case the returned ThreadInfo object will have an empty array of StackTraceElements.

The returned object will hold no details of locked synchronizers or locked object monitors for the specified thread; calls to getLockedMonitors() and getLockedSynchronizers will both return array values.

Specified by:
getThreadInfo in interface java.lang.management.ThreadMXBean
Parameters:
id - the identifier for a thread. Must be a positive number greater than zero.
maxDepth - the maximum number of stack trace entries to be included in the returned ThreadInfo object. Supplying Integer.MAX_VALUE obtains all of the stack trace. Only a positive value is expected.
Returns:
if the supplied id maps to a living thread in the virtual machine (i.e. a started thread which has not yet died), this method returns a ThreadInfoobject corresponding to that thread. Otherwise, returns null.

getThreadUserTime

  1. public long getThreadUserTime(long id)

Description copied from interface: java.lang.management.ThreadMXBean

If supported by the virtual machine, returns the total CPU usage time for the thread with the specified identifier when running in user mode. The returned time will have nanosecond precision but may not have nanosecond accuracy.

Method ThreadMXBean.isThreadCpuTimeSupported()may be used to determine if the CPU timing of threads is supported on the virtual machine. On virtual machines where current thread CPU timing is supported, the method ThreadMXBean.isThreadCpuTimeEnabled()may be used to determine if thread CPU timing is actually enabled.

Specified by:
getThreadUserTime in interface java.lang.management.ThreadMXBean
Parameters:
id - the identifier for a thread. Must be a positive number greater than zero.
Returns:
on virtual machines where thread CPU timing is supported and enabled, and there is a living thread with identifier id, the number of nanoseconds CPU time used by the thread running in user mode. On virtual machines where thread CPU timing is supported but not enabled, or where there is no living thread with identifier id present in the virtual machine, a value of -1 is returned.

If thread CPU timing was disabled when the thread was started then the virtual machine is free to choose any measurement start time between when the virtual machine started up and when thread CPU timing was enabled with a call to ThreadMXBean.setThreadCpuTimeEnabled(boolean).

See Also:
ThreadMXBean.isThreadCpuTimeSupported(), ThreadMXBean.isThreadCpuTimeEnabled()

getTotalStartedThreadCount

  1. public long getTotalStartedThreadCount( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns the number of threads that have been started in this virtual machine since it came into being.
Specified by:
getTotalStartedThreadCount in interface java.lang.management.ThreadMXBean
Returns:
the total number of started threads.

isCurrentThreadCpuTimeSupported

  1. public boolean isCurrentThreadCpuTimeSupported( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns a boolean indication of whether or not the virtual machine supports the CPU timing of the current thread.

Note that this method must return true if ThreadMXBean.isThreadCpuTimeSupported()returns true.

Specified by:
isCurrentThreadCpuTimeSupported in interface java.lang.management.ThreadMXBean
Returns:
true if CPU timing of the current thread is supported, otherwise false.

isThreadContentionMonitoringEnabled

  1. public boolean isThreadContentionMonitoringEnabled( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns a boolean indication of whether or not the monitoring of thread contention situations is enabled on this virtual machine.
Specified by:
isThreadContentionMonitoringEnabled in interface java.lang.management.ThreadMXBean
Returns:
true if thread contention monitoring is enabled, false otherwise.

isThreadContentionMonitoringSupported

  1. public boolean isThreadContentionMonitoringSupported( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns a boolean indication of whether or not the monitoring of thread contention situations is supported on this virtual machine.
Specified by:
isThreadContentionMonitoringSupported in interface java.lang.management.ThreadMXBean
Returns:
true if thread contention monitoring is supported, false otherwise.

isThreadCpuTimeEnabled

  1. public boolean isThreadCpuTimeEnabled( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns a boolean indication of whether or not the CPU timing of threads is enabled on this virtual machine.
Specified by:
isThreadCpuTimeEnabled in interface java.lang.management.ThreadMXBean
Returns:
true if thread CPU timing is enabled, false otherwise.
See Also:
ThreadMXBean.isThreadCpuTimeSupported()

isThreadCpuTimeSupported

  1. public boolean isThreadCpuTimeSupported( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns a boolean indication of whether or not the virtual machine supports the CPU time measurement of any threads (current or otherwise).
Specified by:
isThreadCpuTimeSupported in interface java.lang.management.ThreadMXBean
Returns:
true if the virtual machine supports the CPU timing of threads, false otherwise.

resetPeakThreadCount

  1. public void resetPeakThreadCount( )

Description copied from interface: java.lang.management.ThreadMXBean

Resets the peak thread count to be the current number of threads alive in the virtual machine when the call is made.
Specified by:
resetPeakThreadCount in interface java.lang.management.ThreadMXBean

setThreadContentionMonitoringEnabled

  1. public void setThreadContentionMonitoringEnabled( boolean enable)

Description copied from interface: java.lang.management.ThreadMXBean

Updates the virtual machine to either enable or disable the monitoring of thread contention situations.

If it is supported, the virtual machine will initially not monitor thread contention situations.

Specified by:
setThreadContentionMonitoringEnabled in interface java.lang.management.ThreadMXBean
Parameters:
enable - enable thread contention monitoring if true, otherwise disable thread contention monitoring.
See Also:
ThreadMXBean.isThreadContentionMonitoringSupported()

setThreadCpuTimeEnabled

  1. public void setThreadCpuTimeEnabled( boolean enable)

Description copied from interface: java.lang.management.ThreadMXBean

If supported, updates the virtual machine to either enable or disable the CPU timing of threads.

The default value of this property depends on the underlying operating system on which the virtual machine is running.

Specified by:
setThreadCpuTimeEnabled in interface java.lang.management.ThreadMXBean
Parameters:
enable - enable thread CPU timing if true, otherwise disable thread CPU timing
See Also:
ThreadMXBean.isThreadCpuTimeSupported()

isObjectMonitorUsageSupported

  1. public boolean isObjectMonitorUsageSupported( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns a boolean indication of whether or not the virtual machine supports the monitoring of object monitor usage.
Specified by:
isObjectMonitorUsageSupported in interface java.lang.management.ThreadMXBean
Returns:
true if object monitor usage is permitted, otherwise false

isSynchronizerUsageSupported

  1. public boolean isSynchronizerUsageSupported( )

Description copied from interface: java.lang.management.ThreadMXBean

Returns a boolean indication of whether or not the virtual machine supports the monitoring of ownable synchronizers (synchronizers that make use of the AbstractOwnableSynchronizer type and which are completely owned by a single thread).
Specified by:
isSynchronizerUsageSupported in interface java.lang.management.ThreadMXBean
Returns:
true if synchronizer usage monitoring is permitted, otherwise false

findDeadlockedThreads

  1. public long[] findDeadlockedThreads( )

Description copied from interface: java.lang.management.ThreadMXBean

If supported by the virtual machine, this method can be used to retrieve the long id of all threads currently waiting on object monitors or ownable synchronizers (synchronizers that make use of the AbstractOwnableSynchronizer type and which are completely owned by a single thread). To determine the threads currently deadlocked by object monitors only use the ThreadMXBean.findMonitorDeadlockedThreads() method.

It is recommended that this method be used solely for problem determination analysis and not as a means of managing thread synchronization in a virtual machine. This is because the method may be very expensive to run.

Specified by:
findDeadlockedThreads in interface java.lang.management.ThreadMXBean
Returns:
an array of the identifiers of every thread in the virtual machine that has been detected as currently being in a deadlock situation involving object monitors and ownable synchronizers. If there are no threads in this category a null is returned.
See Also:
ThreadMXBean.isSynchronizerUsageSupported()

dumpAllThreads

  1. public java.lang.management.ThreadInfo[] dumpAllThreads( boolean lockedMonitors,
  2. boolean lockedSynchronizers)

Description copied from interface: java.lang.management.ThreadMXBean

Returns an array of ThreadInfo objects holding information on all threads that were alive when the call was invoked.
Specified by:
dumpAllThreads in interface java.lang.management.ThreadMXBean
Parameters:
lockedMonitors - boolean indication of whether or not information on all currently locked object monitors is to be included in the returned array
lockedSynchronizers - boolean indication of whether or not information on all currently locked ownable synchronizers is to be included in the returned array
Returns:
an array of ThreadInfo objects