|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.util.ThreadMeasurer
public class ThreadMeasurer
Class which measures the threads of a JVM.
This class was adapted from the class
<JDK_HOME>/demo/management/FullThreadDump/src/ThreadMonitor.java
written by Mandy Chung.
This class is multithread safe: the public static methods do not use any state of this class, and the public instance methods are all synchronized. The protected instance methods are not synchronized, and subclass authors should ensure that they are only called from public synchronized methods.
Nested Class Summary | |
---|---|
static class |
ThreadMeasurer.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private boolean |
reportThreadContention
|
private boolean |
reportThreadTimes
|
private ThreadMXBean |
threadMXBean
Contract: is never null. |
Constructor Summary | |
---|---|
ThreadMeasurer()
Constructs an instance which gets thread information from the local JVM. |
|
ThreadMeasurer(MBeanServerConnection server)
Constructs an instance which gets thread information from the JVM specified by server. |
|
ThreadMeasurer(ThreadMXBean threadMXBean)
Constructs an instance which gets thread information from threadMXBean. |
Method Summary | |
---|---|
protected void |
appendThreadInfo(ThreadInfo threadInfo,
StringBuilder sb)
Appends all of the data in threadInfo to sb. |
protected void |
appendThreadInfoArray(ThreadInfo[] threadInfos,
StringBuilder sb)
Appends the data in threadInfos to sb. |
static boolean |
attemptCpuTimeMeasurement(ThreadMXBean threadMXBean)
Trys to ensure that threadMXBean has enabled thread cpu time measurement. |
static boolean |
attemptThreadContentionMonitoring(ThreadMXBean threadMXBean)
Trys to ensure that threadMXBean has enabled thread contention monitoring (i.e. for collecting per-thread statistics about monitor contention). |
String |
getDeadlockState()
Checks if any threads are deadlocked. |
static ThreadMXBean |
getThreadMXBean(MBeanServerConnection server)
Returns a ThreadMXBean instance for the JVM specified by server. |
String |
getThreadState()
Returns a String description of the thread state of the monitored JVM. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final ThreadMXBean threadMXBean
private final boolean reportThreadTimes
private final boolean reportThreadContention
Constructor Detail |
---|
public ThreadMeasurer()
public ThreadMeasurer(MBeanServerConnection server) throws IllegalArgumentException, IOException
IllegalArgumentException
- if server == null
IOException
- if a communication problem occurrs when accessing serverpublic ThreadMeasurer(ThreadMXBean threadMXBean) throws IllegalArgumentException
IllegalArgumentException
- if threadMXBean == nullMethod Detail |
---|
public static ThreadMXBean getThreadMXBean(MBeanServerConnection server) throws IllegalArgumentException, IOException
IllegalArgumentException
- if server == null
IOException
- if a communication problem occurrs when accessing serverpublic static boolean attemptCpuTimeMeasurement(ThreadMXBean threadMXBean) throws IllegalArgumentException
IllegalArgumentException
- if threadMXBean == nullpublic static boolean attemptThreadContentionMonitoring(ThreadMXBean threadMXBean) throws IllegalArgumentException
IllegalArgumentException
- if threadMXBean == nullpublic String getThreadState() throws UnsupportedOperationException
Contract: the result is never null.
UnsupportedOperationException
- if reportThreadTimes
was set to true in the constructor
but some other class called threadMXBean
.setThreadCpuTimeEnabled
(false)
.public String getDeadlockState() throws SecurityException
This method will attempt to find deadlocks in both monitors as well as ownable synchronizers if possible. But if the platform does not support finding deadlock detection in ownable synchronizers, it falls back to examining just monitors.
SecurityException
- if a security manager exists and the caller does not have ManagementPermission("monitor")protected void appendThreadInfoArray(ThreadInfo[] threadInfos, StringBuilder sb) throws UnsupportedOperationException
Skips over any element that is null.
This behavior is critical, because if the threadInfos arg came as a result of calling
ThreadMXBean.getThreadInfo
, then null elements may be present
for threads which died by the time that getThreadInfo was called.
UnsupportedOperationException
- if reportThreadTimes
was set to true in the constructor
but some other class called threadMXBean
.setThreadCpuTimeEnabled
(false)
.protected void appendThreadInfo(ThreadInfo threadInfo, StringBuilder sb) throws UnsupportedOperationException
UnsupportedOperationException
- if reportThreadTimes
was set to true in the constructor
but some other class called threadMXBean
.setThreadCpuTimeEnabled
(false)
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |