Java Code Examples for java.lang.management.ThreadMXBean#isThreadContentionMonitoringSupported()

The following examples show how to use java.lang.management.ThreadMXBean#isThreadContentionMonitoringSupported() . 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: JvmThreadingImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Getter for the "JvmThreadContentionMonitoring" variable.
 */
public EnumJvmThreadContentionMonitoring getJvmThreadContentionMonitoring()
    throws SnmpStatusException {

    ThreadMXBean mbean = getThreadMXBean();

    if(!mbean.isThreadContentionMonitoringSupported()) {
        log.debug("getJvmThreadContentionMonitoring",
                  "Unsupported ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringUnsupported;
    }

    if(mbean.isThreadContentionMonitoringEnabled()) {
        log.debug("getJvmThreadContentionMonitoring",
                  "Enabled ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringEnabled;
    } else {
        log.debug("getJvmThreadContentionMonitoring",
                  "Disabled ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringDisabled;
    }
}
 
Example 2
Source File: JvmThreadingImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Getter for the "JvmThreadContentionMonitoring" variable.
 */
public EnumJvmThreadContentionMonitoring getJvmThreadContentionMonitoring()
    throws SnmpStatusException {

    ThreadMXBean mbean = getThreadMXBean();

    if(!mbean.isThreadContentionMonitoringSupported()) {
        log.debug("getJvmThreadContentionMonitoring",
                  "Unsupported ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringUnsupported;
    }

    if(mbean.isThreadContentionMonitoringEnabled()) {
        log.debug("getJvmThreadContentionMonitoring",
                  "Enabled ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringEnabled;
    } else {
        log.debug("getJvmThreadContentionMonitoring",
                  "Disabled ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringDisabled;
    }
}
 
Example 3
Source File: ThreadDumpProvider.java    From TNT4J with Apache License 2.0 6 votes vote down vote up
@Override
public DumpCollection getDump() {
	Dump dump = new Dump("JavaThreadStack", this);

	ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
	boolean contentionSupported = tmbean.isThreadContentionMonitoringSupported()
			&& tmbean.isThreadContentionMonitoringEnabled();
	boolean cputSupported = tmbean.isThreadCpuTimeSupported() && tmbean.isThreadCpuTimeEnabled();
	dump.add("java.thread.contention.supported", contentionSupported);
	dump.add("java.thread.cpu.supported", cputSupported);

	long[] dead = tmbean.findMonitorDeadlockedThreads();
	dump.add("java.thread.deadlock.count", dead == null ? 0 : dead.length);

	long[] tids = tmbean.getAllThreadIds();
	ThreadInfo[] tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
	for (ThreadInfo ti : tinfos) {
		dump.add(ti.getThreadName() + "-" + ti.getThreadId(), ti);
	}
	return dump;
}
 
Example 4
Source File: JvmThreadInstanceEntryImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstBlockTimeMs" variable.
 */
public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
    long l = 0;

    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();

    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getBlockedTime();

        //Monitoring is disabled
        if(l == -1) l = 0;
    }
    return new Long(l);
}
 
Example 5
Source File: JvmThreadInstanceEntryImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstWaitTimeMs" variable.
 */
public Long getJvmThreadInstWaitTimeMs() throws SnmpStatusException {
    long l = 0;

    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();

    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getWaitedTime();

        //Monitoring is disabled
        if(l == -1) l = 0;
    }
    return new Long(l);
}
 
Example 6
Source File: JvmThreadingImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checker for the "JvmThreadContentionMonitoring" variable.
 */
public void checkJvmThreadContentionMonitoring(
                          EnumJvmThreadContentionMonitoring x)
    throws SnmpStatusException {
    //Can't be set externaly to unsupported state.
    if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) {
        log.debug("checkJvmThreadContentionMonitoring",
                  "Try to set to illegal unsupported value");
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
    }

    if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) ||
        (JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) {

        // The value is valid, but is the feature supported ?
        ThreadMXBean mbean = getThreadMXBean();
        if(mbean.isThreadContentionMonitoringSupported()) return;

        log.debug("checkJvmThreadContentionMonitoring",
                  "Unsupported operation, can't set state");
        throw new
            SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
    }

    log.debug("checkJvmThreadContentionMonitoring",
              "Try to set to unknown value");
    throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
 
Example 7
Source File: JvmThreadInstanceEntryImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstBlockTimeMs" variable.
 */
public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
    long l = 0;

    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();

    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getBlockedTime();

        //Monitoring is disabled
        if(l == -1) l = 0;
    }
    return new Long(l);
}
 
Example 8
Source File: JvmThreadInstanceEntryImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstBlockTimeMs" variable.
 */
public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
    long l = 0;

    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();

    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getBlockedTime();

        //Monitoring is disabled
        if(l == -1) l = 0;
    }
    return new Long(l);
}
 
Example 9
Source File: JvmThreadingImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checker for the "JvmThreadContentionMonitoring" variable.
 */
public void checkJvmThreadContentionMonitoring(
                          EnumJvmThreadContentionMonitoring x)
    throws SnmpStatusException {
    //Can't be set externaly to unsupported state.
    if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) {
        log.debug("checkJvmThreadContentionMonitoring",
                  "Try to set to illegal unsupported value");
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
    }

    if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) ||
        (JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) {

        // The value is valid, but is the feature supported ?
        ThreadMXBean mbean = getThreadMXBean();
        if(mbean.isThreadContentionMonitoringSupported()) return;

        log.debug("checkJvmThreadContentionMonitoring",
                  "Unsupported operation, can't set state");
        throw new
            SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
    }

    log.debug("checkJvmThreadContentionMonitoring",
              "Try to set to unknown value");
    throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
 
Example 10
Source File: JvmThreadInstanceEntryImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstWaitTimeMs" variable.
 */
public Long getJvmThreadInstWaitTimeMs() throws SnmpStatusException {
    long l = 0;

    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();

    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getWaitedTime();

        //Monitoring is disabled
        if(l == -1) l = 0;
    }
    return new Long(l);
}
 
Example 11
Source File: JvmThreadingImpl.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checker for the "JvmThreadContentionMonitoring" variable.
 */
public void checkJvmThreadContentionMonitoring(
                          EnumJvmThreadContentionMonitoring x)
    throws SnmpStatusException {
    //Can't be set externaly to unsupported state.
    if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) {
        log.debug("checkJvmThreadContentionMonitoring",
                  "Try to set to illegal unsupported value");
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
    }

    if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) ||
        (JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) {

        // The value is valid, but is the feature supported ?
        ThreadMXBean mbean = getThreadMXBean();
        if(mbean.isThreadContentionMonitoringSupported()) return;

        log.debug("checkJvmThreadContentionMonitoring",
                  "Unsupported operation, can't set state");
        throw new
            SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
    }

    log.debug("checkJvmThreadContentionMonitoring",
              "Try to set to unknown value");
    throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
 
Example 12
Source File: JvmThreadingImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checker for the "JvmThreadContentionMonitoring" variable.
 */
public void checkJvmThreadContentionMonitoring(
                          EnumJvmThreadContentionMonitoring x)
    throws SnmpStatusException {
    //Can't be set externaly to unsupported state.
    if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) {
        log.debug("checkJvmThreadContentionMonitoring",
                  "Try to set to illegal unsupported value");
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
    }

    if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) ||
        (JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) {

        // The value is valid, but is the feature supported ?
        ThreadMXBean mbean = getThreadMXBean();
        if(mbean.isThreadContentionMonitoringSupported()) return;

        log.debug("checkJvmThreadContentionMonitoring",
                  "Unsupported operation, can't set state");
        throw new
            SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
    }

    log.debug("checkJvmThreadContentionMonitoring",
              "Try to set to unknown value");
    throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
 
Example 13
Source File: JvmThreadInstanceEntryImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstWaitTimeMs" variable.
 */
public Long getJvmThreadInstWaitTimeMs() throws SnmpStatusException {
    long l = 0;

    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();

    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getWaitedTime();

        //Monitoring is disabled
        if(l == -1) l = 0;
    }
    return new Long(l);
}
 
Example 14
Source File: JvmThreadingImpl.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checker for the "JvmThreadContentionMonitoring" variable.
 */
public void checkJvmThreadContentionMonitoring(
                          EnumJvmThreadContentionMonitoring x)
    throws SnmpStatusException {
    //Can't be set externaly to unsupported state.
    if(JvmThreadContentionMonitoringUnsupported.intValue()==x.intValue()) {
        log.debug("checkJvmThreadContentionMonitoring",
                  "Try to set to illegal unsupported value");
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
    }

    if ((JvmThreadContentionMonitoringEnabled.intValue()==x.intValue()) ||
        (JvmThreadContentionMonitoringDisabled.intValue()==x.intValue())) {

        // The value is valid, but is the feature supported ?
        ThreadMXBean mbean = getThreadMXBean();
        if(mbean.isThreadContentionMonitoringSupported()) return;

        log.debug("checkJvmThreadContentionMonitoring",
                  "Unsupported operation, can't set state");
        throw new
            SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
    }

    log.debug("checkJvmThreadContentionMonitoring",
              "Try to set to unknown value");
    throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
 
Example 15
Source File: TrackingLogger.java    From TNT4J with Apache License 2.0 5 votes vote down vote up
/**
 * Check and enable java timing for use by activities
 *
 */
private static void initJavaTiming() {
	ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
	boolean cpuTimingSupported = tmbean.isCurrentThreadCpuTimeSupported();
	if (cpuTimingSupported) {
		tmbean.setThreadCpuTimeEnabled(cpuTimingSupported);
	}
	boolean contTimingSupported = tmbean.isThreadContentionMonitoringSupported();
	if (contTimingSupported) {
		tmbean.setThreadContentionMonitoringEnabled(contTimingSupported);
	}
}
 
Example 16
Source File: JvmThreadInstanceEntryImpl.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadInstBlockTimeMs" variable.
 */
public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
    long l = 0;

    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();

    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getBlockedTime();

        //Monitoring is disabled
        if(l == -1) l = 0;
    }
    return new Long(l);
}
 
Example 17
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 18
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 19
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 20
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 ;
}