Java Code Examples for java.lang.management.ManagementFactory#THREAD_MXBEAN_NAME

The following examples show how to use java.lang.management.ManagementFactory#THREAD_MXBEAN_NAME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmxSupport.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private boolean hasDumpAllThreads() {
    synchronized (hasDumpAllThreadsLock) {
        if (hasDumpAllThreads == null) {
            hasDumpAllThreads = Boolean.FALSE;
            try {
                ObjectName threadObjName = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
                MBeanInfo threadInfo = jmxModel.getMBeanServerConnection().getMBeanInfo(threadObjName);
                if (threadInfo != null) {
                    for (MBeanOperationInfo op : threadInfo.getOperations()) {
                        if ("dumpAllThreads".equals(op.getName())) {
                            hasDumpAllThreads = Boolean.TRUE;
                        }
                    }
                }
            } catch (Exception ex) {
                LOGGER.log(Level.INFO,"hasDumpAllThreads", ex); // NOI18N
            }
        }
        return hasDumpAllThreads.booleanValue();
    }
}
 
Example 2
Source File: VMLogger.java    From openjdk-systemtest with Apache License 2.0 5 votes vote down vote up
private void initialiseServerNames() {
    try {
    	srvRuntimeName  = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
        srvOSName       = new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);
        srvClassName    = new ObjectName(ManagementFactory.CLASS_LOADING_MXBEAN_NAME);

        if (!(compiler.equals(""))) {	
            srvCompName = new ObjectName(ManagementFactory.COMPILATION_MXBEAN_NAME);
        }
                    
        srvThrdName     = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
        srvMemName      = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
        srvLogName      = new ObjectName("java.util.logging:type=Logging");
        srvMemMgrNames  = mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + ",*"), null);
        srvMemPoolNames = mbs.queryNames(new ObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*"), null);
        srvGCNames      = mbs.queryNames(new ObjectName(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*"), null);

    } catch ( MalformedObjectNameException me) {
        Message.logOut("Got a MalformedObjectNameException");
        me.printStackTrace();
        Assert.fail("Got a MalformedObjectNameException");
    } catch ( IOException ie ) {
        Message.logOut("Caught an IOException:");
        ie.printStackTrace();
        Assert.fail("Caught an IOException: \n" + ie.getMessage());
    }	
}
 
Example 3
Source File: ThreadsMemory.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static ObjectName getThreadName() {
    try {
        return new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
    } catch (MalformedObjectNameException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 4
Source File: ThreadsCPU.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private static ObjectName getThreadName() {
    try {
        return new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
    } catch (MalformedObjectNameException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 5
Source File: MBeanDumper.java    From tda with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Constructs a ThreadMonitor object to get thread information
 * in a remote JVM.
 */
public MBeanDumper(MBeanServerConnection server) throws IOException {
   setMBeanServerConnection(server);
   try {
       objname = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
    } catch (MalformedObjectNameException e) {
        // should not reach here
        InternalError ie = new InternalError(e.getMessage());
        ie.initCause(e);
        throw ie;
   }
   parseMBeanInfo(); 
}
 
Example 6
Source File: MXBeanInteropTest1.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private final int doThreadMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ThreadMXBean") ;

    try {
        ObjectName threadName =
                new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(threadName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        ThreadMXBean thread = null ;

        thread =
                JMX.newMXBeanProxy(mbsc,
                threadName,
                ThreadMXBean.class) ;
        System.out.println("findMonitorDeadlockedThreads\t\t"
                + thread.findMonitorDeadlockedThreads());
        long[] threadIDs = thread.getAllThreadIds() ;
        System.out.println("getAllThreadIds\t\t"
                + threadIDs);

        for ( long threadID : threadIDs ) {
            System.out.println("getThreadInfo long\t\t"
                    + thread.getThreadInfo(threadID));
            System.out.println("getThreadInfo long, int\t\t"
                    + thread.getThreadInfo(threadID, 2));
        }

        System.out.println("getThreadInfo long[]\t\t"
                + thread.getThreadInfo(threadIDs));
        System.out.println("getThreadInfo long[], int\t\t"
                + thread.getThreadInfo(threadIDs, 2));
        System.out.println("getDaemonThreadCount\t\t"
                + thread.getDaemonThreadCount());
        System.out.println("getPeakThreadCount\t\t"
                + thread.getPeakThreadCount());
        System.out.println("getThreadCount\t\t"
                + thread.getThreadCount());
        System.out.println("getTotalStartedThreadCount\t\t"
                + thread.getTotalStartedThreadCount());
        boolean supported = thread.isThreadContentionMonitoringSupported() ;
        System.out.println("isThreadContentionMonitoringSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadContentionMonitoringEnabled\t\t"
                    + thread.isThreadContentionMonitoringEnabled());
        }

        supported = thread.isThreadCpuTimeSupported() ;
        System.out.println("isThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadCpuTimeEnabled\t\t"
                    + thread.isThreadCpuTimeEnabled());

            for (long id : threadIDs) {
                System.out.println("getThreadCpuTime(" + id + ")\t\t"
                        + thread.getThreadCpuTime(id));
                System.out.println("getThreadUserTime(" + id + ")\t\t"
                        + thread.getThreadUserTime(id));
            }
        }

        supported = thread.isCurrentThreadCpuTimeSupported() ;
        System.out.println("isCurrentThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("getCurrentThreadCpuTime\t\t"
                    + thread.getCurrentThreadCpuTime());
            System.out.println("getCurrentThreadUserTime\t\t"
                    + thread.getCurrentThreadUserTime());
        }

        thread.resetPeakThreadCount() ;

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 7
Source File: MXBeanInteropTest1.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private final int doThreadMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ThreadMXBean") ;

    try {
        ObjectName threadName =
                new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(threadName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        ThreadMXBean thread = null ;

        thread =
                JMX.newMXBeanProxy(mbsc,
                threadName,
                ThreadMXBean.class) ;
        System.out.println("findMonitorDeadlockedThreads\t\t"
                + thread.findMonitorDeadlockedThreads());
        long[] threadIDs = thread.getAllThreadIds() ;
        System.out.println("getAllThreadIds\t\t"
                + threadIDs);

        for ( long threadID : threadIDs ) {
            System.out.println("getThreadInfo long\t\t"
                    + thread.getThreadInfo(threadID));
            System.out.println("getThreadInfo long, int\t\t"
                    + thread.getThreadInfo(threadID, 2));
        }

        System.out.println("getThreadInfo long[]\t\t"
                + thread.getThreadInfo(threadIDs));
        System.out.println("getThreadInfo long[], int\t\t"
                + thread.getThreadInfo(threadIDs, 2));
        System.out.println("getDaemonThreadCount\t\t"
                + thread.getDaemonThreadCount());
        System.out.println("getPeakThreadCount\t\t"
                + thread.getPeakThreadCount());
        System.out.println("getThreadCount\t\t"
                + thread.getThreadCount());
        System.out.println("getTotalStartedThreadCount\t\t"
                + thread.getTotalStartedThreadCount());
        boolean supported = thread.isThreadContentionMonitoringSupported() ;
        System.out.println("isThreadContentionMonitoringSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadContentionMonitoringEnabled\t\t"
                    + thread.isThreadContentionMonitoringEnabled());
        }

        supported = thread.isThreadCpuTimeSupported() ;
        System.out.println("isThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadCpuTimeEnabled\t\t"
                    + thread.isThreadCpuTimeEnabled());

            for (long id : threadIDs) {
                System.out.println("getThreadCpuTime(" + id + ")\t\t"
                        + thread.getThreadCpuTime(id));
                System.out.println("getThreadUserTime(" + id + ")\t\t"
                        + thread.getThreadUserTime(id));
            }
        }

        supported = thread.isCurrentThreadCpuTimeSupported() ;
        System.out.println("isCurrentThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("getCurrentThreadCpuTime\t\t"
                    + thread.getCurrentThreadCpuTime());
            System.out.println("getCurrentThreadUserTime\t\t"
                    + thread.getCurrentThreadUserTime());
        }

        thread.resetPeakThreadCount() ;

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 8
Source File: MXBeanInteropTest1.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private final int doThreadMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ThreadMXBean") ;

    try {
        ObjectName threadName =
                new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(threadName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        ThreadMXBean thread = null ;

        thread =
                JMX.newMXBeanProxy(mbsc,
                threadName,
                ThreadMXBean.class) ;
        System.out.println("findMonitorDeadlockedThreads\t\t"
                + thread.findMonitorDeadlockedThreads());
        long[] threadIDs = thread.getAllThreadIds() ;
        System.out.println("getAllThreadIds\t\t"
                + threadIDs);

        for ( long threadID : threadIDs ) {
            System.out.println("getThreadInfo long\t\t"
                    + thread.getThreadInfo(threadID));
            System.out.println("getThreadInfo long, int\t\t"
                    + thread.getThreadInfo(threadID, 2));
        }

        System.out.println("getThreadInfo long[]\t\t"
                + thread.getThreadInfo(threadIDs));
        System.out.println("getThreadInfo long[], int\t\t"
                + thread.getThreadInfo(threadIDs, 2));
        System.out.println("getDaemonThreadCount\t\t"
                + thread.getDaemonThreadCount());
        System.out.println("getPeakThreadCount\t\t"
                + thread.getPeakThreadCount());
        System.out.println("getThreadCount\t\t"
                + thread.getThreadCount());
        System.out.println("getTotalStartedThreadCount\t\t"
                + thread.getTotalStartedThreadCount());
        boolean supported = thread.isThreadContentionMonitoringSupported() ;
        System.out.println("isThreadContentionMonitoringSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadContentionMonitoringEnabled\t\t"
                    + thread.isThreadContentionMonitoringEnabled());
        }

        supported = thread.isThreadCpuTimeSupported() ;
        System.out.println("isThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadCpuTimeEnabled\t\t"
                    + thread.isThreadCpuTimeEnabled());

            for (long id : threadIDs) {
                System.out.println("getThreadCpuTime(" + id + ")\t\t"
                        + thread.getThreadCpuTime(id));
                System.out.println("getThreadUserTime(" + id + ")\t\t"
                        + thread.getThreadUserTime(id));
            }
        }

        supported = thread.isCurrentThreadCpuTimeSupported() ;
        System.out.println("isCurrentThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("getCurrentThreadCpuTime\t\t"
                    + thread.getCurrentThreadCpuTime());
            System.out.println("getCurrentThreadUserTime\t\t"
                    + thread.getCurrentThreadUserTime());
        }

        thread.resetPeakThreadCount() ;

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 9
Source File: MXBeanInteropTest1.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
private final int doThreadMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ThreadMXBean") ;

    try {
        ObjectName threadName =
                new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(threadName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        ThreadMXBean thread = null ;

        thread =
                JMX.newMXBeanProxy(mbsc,
                threadName,
                ThreadMXBean.class) ;
        System.out.println("findMonitorDeadlockedThreads\t\t"
                + thread.findMonitorDeadlockedThreads());
        long[] threadIDs = thread.getAllThreadIds() ;
        System.out.println("getAllThreadIds\t\t"
                + threadIDs);

        for ( long threadID : threadIDs ) {
            System.out.println("getThreadInfo long\t\t"
                    + thread.getThreadInfo(threadID));
            System.out.println("getThreadInfo long, int\t\t"
                    + thread.getThreadInfo(threadID, 2));
        }

        System.out.println("getThreadInfo long[]\t\t"
                + thread.getThreadInfo(threadIDs));
        System.out.println("getThreadInfo long[], int\t\t"
                + thread.getThreadInfo(threadIDs, 2));
        System.out.println("getDaemonThreadCount\t\t"
                + thread.getDaemonThreadCount());
        System.out.println("getPeakThreadCount\t\t"
                + thread.getPeakThreadCount());
        System.out.println("getThreadCount\t\t"
                + thread.getThreadCount());
        System.out.println("getTotalStartedThreadCount\t\t"
                + thread.getTotalStartedThreadCount());
        boolean supported = thread.isThreadContentionMonitoringSupported() ;
        System.out.println("isThreadContentionMonitoringSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadContentionMonitoringEnabled\t\t"
                    + thread.isThreadContentionMonitoringEnabled());
        }

        supported = thread.isThreadCpuTimeSupported() ;
        System.out.println("isThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadCpuTimeEnabled\t\t"
                    + thread.isThreadCpuTimeEnabled());

            for (long id : threadIDs) {
                System.out.println("getThreadCpuTime(" + id + ")\t\t"
                        + thread.getThreadCpuTime(id));
                System.out.println("getThreadUserTime(" + id + ")\t\t"
                        + thread.getThreadUserTime(id));
            }
        }

        supported = thread.isCurrentThreadCpuTimeSupported() ;
        System.out.println("isCurrentThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("getCurrentThreadCpuTime\t\t"
                    + thread.getCurrentThreadCpuTime());
            System.out.println("getCurrentThreadUserTime\t\t"
                    + thread.getCurrentThreadUserTime());
        }

        thread.resetPeakThreadCount() ;

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 10
Source File: MXBeanInteropTest1.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private final int doThreadMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ThreadMXBean") ;

    try {
        ObjectName threadName =
                new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(threadName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        ThreadMXBean thread = null ;

        thread =
                JMX.newMXBeanProxy(mbsc,
                threadName,
                ThreadMXBean.class) ;
        System.out.println("findMonitorDeadlockedThreads\t\t"
                + thread.findMonitorDeadlockedThreads());
        long[] threadIDs = thread.getAllThreadIds() ;
        System.out.println("getAllThreadIds\t\t"
                + threadIDs);

        for ( long threadID : threadIDs ) {
            System.out.println("getThreadInfo long\t\t"
                    + thread.getThreadInfo(threadID));
            System.out.println("getThreadInfo long, int\t\t"
                    + thread.getThreadInfo(threadID, 2));
        }

        System.out.println("getThreadInfo long[]\t\t"
                + thread.getThreadInfo(threadIDs));
        System.out.println("getThreadInfo long[], int\t\t"
                + thread.getThreadInfo(threadIDs, 2));
        System.out.println("getDaemonThreadCount\t\t"
                + thread.getDaemonThreadCount());
        System.out.println("getPeakThreadCount\t\t"
                + thread.getPeakThreadCount());
        System.out.println("getThreadCount\t\t"
                + thread.getThreadCount());
        System.out.println("getTotalStartedThreadCount\t\t"
                + thread.getTotalStartedThreadCount());
        boolean supported = thread.isThreadContentionMonitoringSupported() ;
        System.out.println("isThreadContentionMonitoringSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadContentionMonitoringEnabled\t\t"
                    + thread.isThreadContentionMonitoringEnabled());
        }

        supported = thread.isThreadCpuTimeSupported() ;
        System.out.println("isThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadCpuTimeEnabled\t\t"
                    + thread.isThreadCpuTimeEnabled());

            for (long id : threadIDs) {
                System.out.println("getThreadCpuTime(" + id + ")\t\t"
                        + thread.getThreadCpuTime(id));
                System.out.println("getThreadUserTime(" + id + ")\t\t"
                        + thread.getThreadUserTime(id));
            }
        }

        supported = thread.isCurrentThreadCpuTimeSupported() ;
        System.out.println("isCurrentThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("getCurrentThreadCpuTime\t\t"
                    + thread.getCurrentThreadCpuTime());
            System.out.println("getCurrentThreadUserTime\t\t"
                    + thread.getCurrentThreadUserTime());
        }

        thread.resetPeakThreadCount() ;

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 11
Source File: MXBeanInteropTest1.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private final int doThreadMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ThreadMXBean") ;

    try {
        ObjectName threadName =
                new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(threadName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        ThreadMXBean thread = null ;

        thread =
                JMX.newMXBeanProxy(mbsc,
                threadName,
                ThreadMXBean.class) ;
        System.out.println("findMonitorDeadlockedThreads\t\t"
                + thread.findMonitorDeadlockedThreads());
        long[] threadIDs = thread.getAllThreadIds() ;
        System.out.println("getAllThreadIds\t\t"
                + threadIDs);

        for ( long threadID : threadIDs ) {
            System.out.println("getThreadInfo long\t\t"
                    + thread.getThreadInfo(threadID));
            System.out.println("getThreadInfo long, int\t\t"
                    + thread.getThreadInfo(threadID, 2));
        }

        System.out.println("getThreadInfo long[]\t\t"
                + thread.getThreadInfo(threadIDs));
        System.out.println("getThreadInfo long[], int\t\t"
                + thread.getThreadInfo(threadIDs, 2));
        System.out.println("getDaemonThreadCount\t\t"
                + thread.getDaemonThreadCount());
        System.out.println("getPeakThreadCount\t\t"
                + thread.getPeakThreadCount());
        System.out.println("getThreadCount\t\t"
                + thread.getThreadCount());
        System.out.println("getTotalStartedThreadCount\t\t"
                + thread.getTotalStartedThreadCount());
        boolean supported = thread.isThreadContentionMonitoringSupported() ;
        System.out.println("isThreadContentionMonitoringSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadContentionMonitoringEnabled\t\t"
                    + thread.isThreadContentionMonitoringEnabled());
        }

        supported = thread.isThreadCpuTimeSupported() ;
        System.out.println("isThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadCpuTimeEnabled\t\t"
                    + thread.isThreadCpuTimeEnabled());

            for (long id : threadIDs) {
                System.out.println("getThreadCpuTime(" + id + ")\t\t"
                        + thread.getThreadCpuTime(id));
                System.out.println("getThreadUserTime(" + id + ")\t\t"
                        + thread.getThreadUserTime(id));
            }
        }

        supported = thread.isCurrentThreadCpuTimeSupported() ;
        System.out.println("isCurrentThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("getCurrentThreadCpuTime\t\t"
                    + thread.getCurrentThreadCpuTime());
            System.out.println("getCurrentThreadUserTime\t\t"
                    + thread.getCurrentThreadUserTime());
        }

        thread.resetPeakThreadCount() ;

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}
 
Example 12
Source File: MXBeanInteropTest1.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private final int doThreadMXBeanTest(MBeanServerConnection mbsc) {
    int errorCount = 0 ;
    System.out.println("---- ThreadMXBean") ;

    try {
        ObjectName threadName =
                new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME) ;
        MBeanInfo mbInfo = mbsc.getMBeanInfo(threadName);
        errorCount += checkNonEmpty(mbInfo);
        System.out.println("getMBeanInfo\t\t" + mbInfo);
        ThreadMXBean thread = null ;

        thread =
                JMX.newMXBeanProxy(mbsc,
                threadName,
                ThreadMXBean.class) ;
        System.out.println("findMonitorDeadlockedThreads\t\t"
                + thread.findMonitorDeadlockedThreads());
        long[] threadIDs = thread.getAllThreadIds() ;
        System.out.println("getAllThreadIds\t\t"
                + threadIDs);

        for ( long threadID : threadIDs ) {
            System.out.println("getThreadInfo long\t\t"
                    + thread.getThreadInfo(threadID));
            System.out.println("getThreadInfo long, int\t\t"
                    + thread.getThreadInfo(threadID, 2));
        }

        System.out.println("getThreadInfo long[]\t\t"
                + thread.getThreadInfo(threadIDs));
        System.out.println("getThreadInfo long[], int\t\t"
                + thread.getThreadInfo(threadIDs, 2));
        System.out.println("getDaemonThreadCount\t\t"
                + thread.getDaemonThreadCount());
        System.out.println("getPeakThreadCount\t\t"
                + thread.getPeakThreadCount());
        System.out.println("getThreadCount\t\t"
                + thread.getThreadCount());
        System.out.println("getTotalStartedThreadCount\t\t"
                + thread.getTotalStartedThreadCount());
        boolean supported = thread.isThreadContentionMonitoringSupported() ;
        System.out.println("isThreadContentionMonitoringSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadContentionMonitoringEnabled\t\t"
                    + thread.isThreadContentionMonitoringEnabled());
        }

        supported = thread.isThreadCpuTimeSupported() ;
        System.out.println("isThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("isThreadCpuTimeEnabled\t\t"
                    + thread.isThreadCpuTimeEnabled());

            for (long id : threadIDs) {
                System.out.println("getThreadCpuTime(" + id + ")\t\t"
                        + thread.getThreadCpuTime(id));
                System.out.println("getThreadUserTime(" + id + ")\t\t"
                        + thread.getThreadUserTime(id));
            }
        }

        supported = thread.isCurrentThreadCpuTimeSupported() ;
        System.out.println("isCurrentThreadCpuTimeSupported\t\t"
                + supported);

        if ( supported ) {
            System.out.println("getCurrentThreadCpuTime\t\t"
                    + thread.getCurrentThreadCpuTime());
            System.out.println("getCurrentThreadUserTime\t\t"
                    + thread.getCurrentThreadUserTime());
        }

        thread.resetPeakThreadCount() ;

        System.out.println("---- OK\n") ;
    } catch (Exception e) {
        Utils.printThrowable(e, true) ;
        errorCount++ ;
        System.out.println("---- ERROR\n") ;
    }

    return errorCount ;
}