< prev index next >

jdk/src/java.management/share/classes/sun/management/ThreadImpl.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -24,97 +24,105 @@
  */
 
 package sun.management;
 
 import java.lang.management.ManagementFactory;
-
 import java.lang.management.ThreadInfo;
-
+import java.lang.management.ThreadMXBean;
 import javax.management.ObjectName;
 
 /**
- * Implementation class for the thread subsystem.
- * Standard and committed hotspot-specific metrics if any.
- *
- * ManagementFactory.getThreadMXBean() returns an instance
- * of this class.
+ * Implementation for java.lang.management.ThreadMXBean as well as providing the 
+ * supporting method for com.sun.management.ThreadMXBean. 
+ * The supporting method for com.sun.management.ThreadMXBean can be moved to 
+ * jdk.management in the future. 
  */
-class ThreadImpl implements com.sun.management.ThreadMXBean {
 
+public class ThreadImpl implements ThreadMXBean {
     private final VMManagement jvm;
 
     // default for thread contention monitoring is disabled.
     private boolean contentionMonitoringEnabled = false;
     private boolean cpuTimeEnabled;
     private boolean allocatedMemoryEnabled;
 
     /**
      * Constructor of ThreadImpl class.
      */
-    ThreadImpl(VMManagement vm) {
+    protected ThreadImpl(VMManagement vm) {
         this.jvm = vm;
         this.cpuTimeEnabled = jvm.isThreadCpuTimeEnabled();
         this.allocatedMemoryEnabled = jvm.isThreadAllocatedMemoryEnabled();
     }
 
+    @Override
     public int getThreadCount() {
         return jvm.getLiveThreadCount();
     }
 
+    @Override
     public int getPeakThreadCount() {
         return jvm.getPeakThreadCount();
     }
 
+    @Override
     public long getTotalStartedThreadCount() {
         return jvm.getTotalThreadCount();
     }
 
+    @Override
     public int getDaemonThreadCount() {
         return jvm.getDaemonThreadCount();
     }
 
+    @Override
     public boolean isThreadContentionMonitoringSupported() {
         return jvm.isThreadContentionMonitoringSupported();
     }
 
+    @Override
     public synchronized boolean isThreadContentionMonitoringEnabled() {
        if (!isThreadContentionMonitoringSupported()) {
             throw new UnsupportedOperationException(
                 "Thread contention monitoring is not supported.");
         }
         return contentionMonitoringEnabled;
     }
 
+    @Override
     public boolean isThreadCpuTimeSupported() {
         return jvm.isOtherThreadCpuTimeSupported();
     }
 
+    @Override
     public boolean isCurrentThreadCpuTimeSupported() {
         return jvm.isCurrentThreadCpuTimeSupported();
     }
 
-    public boolean isThreadAllocatedMemorySupported() {
+    protected boolean isThreadAllocatedMemorySupported() {
         return jvm.isThreadAllocatedMemorySupported();
     }
 
+    @Override
     public boolean isThreadCpuTimeEnabled() {
         if (!isThreadCpuTimeSupported() &&
             !isCurrentThreadCpuTimeSupported()) {
             throw new UnsupportedOperationException(
                 "Thread CPU time measurement is not supported");
         }
         return cpuTimeEnabled;
     }
 
-    public boolean isThreadAllocatedMemoryEnabled() {
+    protected boolean isThreadAllocatedMemoryEnabled() {
         if (!isThreadAllocatedMemorySupported()) {
             throw new UnsupportedOperationException(
                 "Thread allocated memory measurement is not supported");
         }
         return allocatedMemoryEnabled;
     }
 
+    @Override
     public long[] getAllThreadIds() {
         Util.checkMonitorAccess();
 
         Thread[] threads = getThreads();
         int length = threads.length;

@@ -124,24 +132,27 @@
             ids[i] = t.getId();
         }
         return ids;
     }
 
+    @Override
     public ThreadInfo getThreadInfo(long id) {
         long[] ids = new long[1];
         ids[0] = id;
         final ThreadInfo[] infos = getThreadInfo(ids, 0);
         return infos[0];
     }
 
+    @Override
     public ThreadInfo getThreadInfo(long id, int maxDepth) {
         long[] ids = new long[1];
         ids[0] = id;
         final ThreadInfo[] infos = getThreadInfo(ids, maxDepth);
         return infos[0];
     }
 
+    @Override
     public ThreadInfo[] getThreadInfo(long[] ids) {
         return getThreadInfo(ids, 0);
     }
 
     private void verifyThreadIds(long[] ids) {

@@ -155,10 +166,11 @@
                     "Invalid thread ID parameter: " + ids[i]);
             }
         }
     }
 
+    @Override
     public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) {
         verifyThreadIds(ids);
 
         if (maxDepth < 0) {
             throw new IllegalArgumentException(

@@ -174,10 +186,11 @@
             getThreadInfo1(ids, maxDepth, infos);
         }
         return infos;
     }
 
+    @Override
     public void setThreadContentionMonitoringEnabled(boolean enable) {
         if (!isThreadContentionMonitoringSupported()) {
             throw new UnsupportedOperationException(
                 "Thread contention monitoring is not supported");
         }

@@ -207,17 +220,19 @@
                 "Current thread CPU time measurement is not supported.");
         }
         return isThreadCpuTimeEnabled();
     }
 
+    @Override
     public long getCurrentThreadCpuTime() {
         if (verifyCurrentThreadCpuTime()) {
             return getThreadTotalCpuTime0(0);
         }
         return -1;
     }
 
+    @Override
     public long getThreadCpuTime(long id) {
         long[] ids = new long[1];
         ids[0] = id;
         final long[] times = getThreadCpuTime(ids);
         return times[0];

@@ -245,11 +260,11 @@
         }
 
         return isThreadCpuTimeEnabled();
     }
 
-    public long[] getThreadCpuTime(long[] ids) {
+    protected long[] getThreadCpuTime(long[] ids) {
         boolean verified = verifyThreadCpuTime(ids);
 
         int length = ids.length;
         long[] times = new long[length];
         java.util.Arrays.fill(times, -1);

@@ -266,25 +281,27 @@
             }
         }
         return times;
     }
 
+    @Override
     public long getCurrentThreadUserTime() {
         if (verifyCurrentThreadCpuTime()) {
             return getThreadUserCpuTime0(0);
         }
         return -1;
     }
 
+    @Override
     public long getThreadUserTime(long id) {
         long[] ids = new long[1];
         ids[0] = id;
         final long[] times = getThreadUserTime(ids);
         return times[0];
     }
 
-    public long[] getThreadUserTime(long[] ids) {
+    protected long[] getThreadUserTime(long[] ids) {
         boolean verified = verifyThreadCpuTime(ids);
 
         int length = ids.length;
         long[] times = new long[length];
         java.util.Arrays.fill(times, -1);

@@ -301,10 +318,11 @@
             }
         }
         return times;
     }
 
+    @Override
     public void setThreadCpuTimeEnabled(boolean enable) {
         if (!isThreadCpuTimeSupported() &&
             !isCurrentThreadCpuTimeSupported()) {
             throw new UnsupportedOperationException(
                 "Thread CPU time measurement is not supported");

@@ -318,11 +336,11 @@
                 cpuTimeEnabled = enable;
             }
         }
     }
 
-    public long getThreadAllocatedBytes(long id) {
+    protected long getThreadAllocatedBytes(long id) {
         long[] ids = new long[1];
         ids[0] = id;
         final long[] sizes = getThreadAllocatedBytes(ids);
         return sizes[0];
     }

@@ -337,11 +355,11 @@
         }
 
         return isThreadAllocatedMemoryEnabled();
     }
 
-    public long[] getThreadAllocatedBytes(long[] ids) {
+    protected long[] getThreadAllocatedBytes(long[] ids) {
         boolean verified = verifyThreadAllocatedMemory(ids);
 
         long[] sizes = new long[ids.length];
         java.util.Arrays.fill(sizes, -1);
 

@@ -349,11 +367,11 @@
             getThreadAllocatedMemory1(ids, sizes);
         }
         return sizes;
     }
 
-    public void setThreadAllocatedMemoryEnabled(boolean enable) {
+    protected void setThreadAllocatedMemoryEnabled(boolean enable) {
         if (!isThreadAllocatedMemorySupported()) {
             throw new UnsupportedOperationException(
                 "Thread allocated memory measurement is not supported.");
         }
 

@@ -365,10 +383,11 @@
                 allocatedMemoryEnabled = enable;
             }
         }
     }
 
+    @Override
     public long[] findMonitorDeadlockedThreads() {
         Util.checkMonitorAccess();
 
         Thread[] threads = findMonitorDeadlockedThreads0();
         if (threads == null) {

@@ -381,10 +400,11 @@
             ids[i] = t.getId();
         }
         return ids;
     }
 
+    @Override
     public long[] findDeadlockedThreads() {
         if (!isSynchronizerUsageSupported()) {
             throw new UnsupportedOperationException(
                 "Monitoring of Synchronizer Usage is not supported.");
         }

@@ -402,19 +422,22 @@
             ids[i] = t.getId();
         }
         return ids;
     }
 
+    @Override
     public void resetPeakThreadCount() {
         Util.checkControlAccess();
         resetPeakThreadCount0();
     }
 
+    @Override
     public boolean isObjectMonitorUsageSupported() {
         return jvm.isObjectMonitorUsageSupported();
     }
 
+    @Override
     public boolean isSynchronizerUsageSupported() {
         return jvm.isSynchronizerUsageSupported();
     }
 
     private void verifyDumpThreads(boolean lockedMonitors,

@@ -430,18 +453,20 @@
         }
 
         Util.checkMonitorAccess();
     }
 
+    @Override
     public ThreadInfo[] getThreadInfo(long[] ids,
                                       boolean lockedMonitors,
                                       boolean lockedSynchronizers) {
         verifyThreadIds(ids);
         verifyDumpThreads(lockedMonitors, lockedSynchronizers);
         return dumpThreads0(ids, lockedMonitors, lockedSynchronizers);
     }
 
+    @Override
     public ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
                                        boolean lockedSynchronizers) {
         verifyDumpThreads(lockedMonitors, lockedSynchronizers);
         return dumpThreads0(null, lockedMonitors, lockedSynchronizers);
     }

@@ -467,10 +492,11 @@
                                                     boolean lockedSynchronizers);
 
     // tid == 0 to reset contention times for all threads
     private static native void resetContentionTimes0(long tid);
 
+    @Override
     public ObjectName getObjectName() {
         return Util.newObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
     }
 
 }
< prev index next >