Example usage for java.lang.management ThreadMXBean setThreadContentionMonitoringEnabled

List of usage examples for java.lang.management ThreadMXBean setThreadContentionMonitoringEnabled

Introduction

In this page you can find the example usage for java.lang.management ThreadMXBean setThreadContentionMonitoringEnabled.

Prototype

public void setThreadContentionMonitoringEnabled(boolean enable);

Source Link

Document

Enables or disables thread contention monitoring.

Usage

From source file:io.pcp.parfait.benchmark.CPUThreadTest.java

private void runBenchmark(boolean cpuTracingEnabled, CPUThreadTestRunner.CpuLookupMethod cpuLookupMethod) {
    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    List<CPUThreadTestRunner> executions = newArrayList();

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    threadBean.setThreadCpuTimeEnabled(cpuTracingEnabled);

    threadBean.setThreadContentionMonitoringEnabled(true);

    long begin = currentTimeMillis();

    for (int i = 0; i < numThreads; i++) {
        CPUThreadTestRunner cpuThreadTestRunner = new CPUThreadTestRunner(iterations, cpuLookupMethod);
        executorService.execute(cpuThreadTestRunner);
        executions.add(cpuThreadTestRunner);
    }/*from   w w  w .java 2 s. c o  m*/

    awaitExecutionCompletion(executorService);

    long end = currentTimeMillis();
    long timeTakenms = end - begin;

    report(executions, timeTakenms, iterations, cpuTracingEnabled, cpuLookupMethod);
}

From source file:com.google.dart.tools.core.DartCore.java

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);

    CmdLineOptions.setOptions(CmdLineOptions.parseCmdLine(Platform.getApplicationArgs()));
    CmdLineOptions.getOptions().printWarnings();

    if (DartCoreDebug.PERF_THREAD_CONTENTION_MONIOR) {
        try {/*from w w w.  j a  v  a  2  s  .  c  o m*/
            java.lang.management.ThreadMXBean th = ManagementFactory.getThreadMXBean();
            th.setThreadContentionMonitoringEnabled(true);
        } catch (UnsupportedOperationException e) {
        }
    }

    AnalysisEngine analysisEngine = AnalysisEngine.getInstance();
    analysisEngine.setLogger(new Logger() {
        @Override
        public void logError(String message) {
            DartCore.logError(message);
        }

        @Override
        public void logError(String message, Throwable exception) {
            DartCore.logError(message, exception);
        }

        @Override
        public void logInformation(String message) {
            DartCore.logInformation(message);
        }

        @Override
        public void logInformation(String message, Throwable exception) {
            DartCore.logInformation(message, exception);
        }
    });
    Logging.setLogger(new com.google.dart.server.utilities.logging.Logger() {
        @Override
        public void logError(String message) {
            DartCore.logError(message);
        }

        @Override
        public void logError(String message, Throwable exception) {
            DartCore.logError(message, exception);
        }

        @Override
        public void logInformation(String message) {
            DartCore.logInformation(message);
        }

        @Override
        public void logInformation(String message, Throwable exception) {
            DartCore.logInformation(message, exception);
        }
    });

    DartSdkManager.getManager().addSdkListener(this);
    if (!DartCoreDebug.ENABLE_ANALYSIS_SERVER) {
        getProjectManager().hookListeners();
    } else {
        getAnalysisServer();
    }
}