diff options
| author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-07-01 11:37:57 +0000 |
|---|---|---|
| committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2006-07-01 11:37:57 +0000 |
| commit | 1ecc92ee201bc12786c458470480c49ff6375d4c (patch) | |
| tree | de0cbf701df2c4712385ef454f5db36db1802b92 /java/lang/management/ThreadInfo.java | |
| parent | 1dcb1d0057fb785bab986cd7a20391349bf60969 (diff) | |
| download | classpath-1ecc92ee201bc12786c458470480c49ff6375d4c.tar.gz | |
2006-07-01 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/java/lang/management/BeanImpl.java:
New superclass for all bean implementations.
* gnu/java/lang/management/ClassLoadingMXBeanImpl.java:
Extend BeanImpl and call permission code there.
* gnu/java/lang/management/OperatingSystemMXBeanImpl.java:
Extend BeanImpl.
* gnu/java/lang/management/RuntimeMXBeanImpl.java:
Extend BeanImpl and call permission code there.
* gnu/java/lang/management/ThreadMXBeanImpl.java:
New file.
* java/lang/management/ManagementFactory.java:
(getThreadMXBean()): Implemented.
* java/lang/management/ThreadInfo.java:
(ThreadInfo(Thread,int)): Replaced...
(ThreadInfo(Thread,long,long,Object,Thread,long,long,
boolean, boolean, StackTraceElement[])): with this.
(getBlockedCount()): Refactored to use local variables.
(getBlockedTime()): Likewise.
(getLockName()): Likewise.
(getLockOwnerId()): Likewise.
(getLockOwnerName()): Likewise.
(getStackTrace()): Likewise.
(getWaitedCount()): Likewise.
(getWaitedTime()): Likewise.
(isInNative()): Likewise.
(isSuspended()): Likewise.
(toString()): Changed to use new local variables.
* java/lang/management/ThreadMXBean.java:
(getThreadInfo(long, int)): Corrected documentation.
(getThreadInfo(long[], int)): Likewise.
* vm/reference/gnu/java/lang/management/VMThreadMXBeanImpl.java:
New file.
* vm/reference/java/lang/management/VMThreadInfo.java:
Removed.
Diffstat (limited to 'java/lang/management/ThreadInfo.java')
| -rw-r--r-- | java/lang/management/ThreadInfo.java | 118 |
1 files changed, 100 insertions, 18 deletions
diff --git a/java/lang/management/ThreadInfo.java b/java/lang/management/ThreadInfo.java index a5555cbe6..d172b16ef 100644 --- a/java/lang/management/ThreadInfo.java +++ b/java/lang/management/ThreadInfo.java @@ -88,9 +88,57 @@ public class ThreadInfo private Thread thread; /** - * The maximum depth of the stack traces for this thread. + * The number of times the thread has been blocked. */ - private int maxDepth; + private long blockedCount; + + /** + * The accumulated number of milliseconds the thread has + * been blocked (used only with thread contention monitoring + * support). + */ + private long blockedTime; + + /** + * The monitor lock on which this thread is blocked + * (if any). + */ + private Object lock; + + /** + * The thread which owns the monitor lock on which this + * thread is blocked, or <code>null</code> if there is + * no owner. + */ + private Thread lockOwner; + + /** + * The number of times the thread has been in a waiting + * state. + */ + private long waitedCount; + + /** + * The accumulated number of milliseconds the thread has + * been waiting (used only with thread contention monitoring + * support). + */ + private long waitedTime; + + /** + * True if the thread is in a native method. + */ + private boolean isInNative; + + /** + * True if the thread is suspended. + */ + private boolean isSuspended; + + /** + * The stack trace of the thread. + */ + private StackTraceElement[] trace; /** * Cache a local reference to the thread management bean. @@ -103,11 +151,41 @@ public class ThreadInfo * * @param thread the thread on which the new instance * will be based. + * @param blockedCount the number of times the thread + * has been blocked. + * @param blockedTime the accumulated number of milliseconds + * the specified thread has been blocked + * (only used with contention monitoring enabled) + * @param lock the monitor lock the thread is waiting for + * (only used if blocked) + * @param lockOwner the thread which owns the monitor lock, or + * <code>null</code> if it doesn't have an owner + * (only used if blocked) + * @param waitedCount the number of times the thread has been in a + * waiting state. + * @param waitedTime the accumulated number of milliseconds the + * specified thread has been waiting + * (only used with contention monitoring enabled) + * @param isInNative true if the thread is in a native method. + * @param isSuspended true if the thread is suspended. + * @param trace the stack trace of the thread to a pre-determined + * depth (see VMThreadMXBeanImpl) */ - ThreadInfo(Thread thread, int maxDepth) + private ThreadInfo(Thread thread, long blockedCount, long blockedTime, + Object lock, Thread lockOwner, long waitedCount, + long waitedTime, boolean isInNative, boolean isSuspended, + StackTraceElement[] trace) { this.thread = thread; - this.maxDepth = maxDepth; + this.blockedCount = blockedCount; + this.blockedTime = blockedTime; + this.lock = lock; + this.lockOwner = lockOwner; + this.waitedCount = waitedCount; + this.waitedTime = waitedTime; + this.isInNative = isInNative; + this.isSuspended = isSuspended; + this.trace = trace; } /** @@ -123,7 +201,7 @@ public class ThreadInfo */ public long getBlockedCount() { - return VMThreadInfo.getBlockedCount(thread); + return blockedCount; } /** @@ -161,7 +239,7 @@ public class ThreadInfo bean = ManagementFactory.getThreadMXBean(); // Will throw UnsupportedOperationException for us if (bean.isThreadContentionMonitoringEnabled()) - return VMThreadInfo.getBlockedTime(thread); + return blockedTime; else return -1; } @@ -196,7 +274,6 @@ public class ThreadInfo { if (thread.getState().equals("BLOCKED")) return null; - Object lock = VMThreadInfo.getLock(thread); return lock.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(lock)); } @@ -216,7 +293,6 @@ public class ThreadInfo { if (thread.getState().equals("BLOCKED")) return -1; - Thread lockOwner = VMThreadInfo.getLockOwner(thread); if (lockOwner == null) return -1; return lockOwner.getId(); @@ -237,7 +313,6 @@ public class ThreadInfo { if (thread.getState().equals("BLOCKED")) return null; - Thread lockOwner = VMThreadInfo.getLockOwner(thread); if (lockOwner == null) return null; return lockOwner.getName(); @@ -264,9 +339,7 @@ public class ThreadInfo */ public StackTraceElement[] getStackTrace() { - if (maxDepth == 0) - return new StackTraceElement[0]; - return VMThreadInfo.getStackTrace(thread, maxDepth); + return trace; } /** @@ -316,7 +389,7 @@ public class ThreadInfo */ public long getWaitedCount() { - return VMThreadInfo.getWaitedCount(thread); + return waitedCount; } /** @@ -355,7 +428,7 @@ public class ThreadInfo bean = ManagementFactory.getThreadMXBean(); // Will throw UnsupportedOperationException for us if (bean.isThreadContentionMonitoringEnabled()) - return VMThreadInfo.getWaitedTime(thread); + return waitedTime; else return -1; } @@ -371,7 +444,7 @@ public class ThreadInfo */ public boolean isInNative() { - return VMThreadInfo.isInNative(thread); + return isInNative; } /** @@ -382,7 +455,7 @@ public class ThreadInfo */ public boolean isSuspended() { - return VMThreadInfo.isSuspended(thread); + return isSuspended; } /** @@ -397,9 +470,18 @@ public class ThreadInfo */ public String toString() { + String state = thread.getState(); return getClass().getName() + - "[id=" + thread.getId() + ", maxDepth=" + - maxDepth + "]"; + "[id=" + thread.getId() + + ", name=" + thread.getName() + + ", state=" + state + + ", blockedCount=" + blockedCount + + ", waitedCount=" + waitedCount + + ", isInNative=" + isInNative + + ", isSuspended=" + isSuspended + + (state.equals("BLOCKED") ? ", lock=" + lock + + ", lockOwner=" + lockOwner : "") + + "]"; } } |
