Example usage for java.lang.management ThreadMXBean isThreadContentionMonitoringEnabled

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

Introduction

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

Prototype

public boolean isThreadContentionMonitoringEnabled();

Source Link

Document

Tests if thread contention monitoring is enabled.

Usage

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

public static void main(String[] args) throws InterruptedException, UnknownHostException {
    int numThreads = args.length < 1 ? Runtime.getRuntime().availableProcessors() : Integer.valueOf(args[0]);
    int numCounters = 1000;
    int iterations = 10000;

    ReportHelper.environmentReportHeader();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    System.out.printf("Thread Contention Supported: %s, Enabled by default: %s\n",
            threadMXBean.isThreadContentionMonitoringSupported(),
            threadMXBean.isThreadContentionMonitoringEnabled());
    System.out.printf("numThreads: %d, numCounters=%d, iterations=%d\n", numThreads, numCounters, iterations);

    new StandardMetricThroughPutBenchmark(numThreads, numCounters, iterations, false, false).runBenchmark();
    new StandardMetricThroughPutBenchmark(numThreads, numCounters, iterations, true, false).runBenchmark();
    new StandardMetricThroughPutBenchmark(numThreads, numCounters, iterations, true, true).runBenchmark();

    // now do it all again reverse, in case there's any JVM warmup issues unfairly treating the first/last runs
    new StandardMetricThroughPutBenchmark(numThreads, numCounters, iterations, true, true).runBenchmark();
    new StandardMetricThroughPutBenchmark(numThreads, numCounters, iterations, true, false).runBenchmark();
    new StandardMetricThroughPutBenchmark(numThreads, numCounters, iterations, false, false).runBenchmark();
}

From source file:org.apache.tajo.master.querymaster.QueryMasterRunner.java

public static void printThreadInfo(PrintWriter stream, String title) {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    final int STACK_DEPTH = 60;
    boolean contention = threadBean.isThreadContentionMonitoringEnabled();
    long[] threadIds = threadBean.getAllThreadIds();
    stream.println("Process Thread Dump: " + title);
    stream.println(threadIds.length + " active threads");
    for (long tid : threadIds) {
        ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH);
        if (info == null) {
            stream.println("  Inactive");
            continue;
        }//from   www .jav  a 2s  .c om
        stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":");
        Thread.State state = info.getThreadState();
        stream.println("  State: " + state);
        stream.println("  Blocked count: " + info.getBlockedCount());
        stream.println("  Waited count: " + info.getWaitedCount());
        if (contention) {
            stream.println("  Blocked time: " + info.getBlockedTime());
            stream.println("  Waited time: " + info.getWaitedTime());
        }
        if (state == Thread.State.WAITING) {
            stream.println("  Waiting on " + info.getLockName());
        } else if (state == Thread.State.BLOCKED) {
            stream.println("  Blocked on " + info.getLockName());
            stream.println("  Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName()));
        }
        stream.println("  Stack:");
        for (StackTraceElement frame : info.getStackTrace()) {
            stream.println("    " + frame.toString());
        }
    }
    stream.flush();
}