Search in sources :

Example 1 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project flink by apache.

the class TaskExecutorMetricsInitializer method instantiateThreadMetrics.

private static void instantiateThreadMetrics(MetricGroup metrics) {
    final ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
    metrics.<Integer, Gauge<Integer>>gauge("Count", new Gauge<Integer>() {

        @Override
        public Integer getValue() {
            return mxBean.getThreadCount();
        }
    });
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) Gauge(org.apache.flink.metrics.Gauge)

Example 2 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project hadoop by apache.

the class TimedOutTestsListener method buildDeadlockInfo.

static String buildDeadlockInfo() {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long[] threadIds = threadBean.findMonitorDeadlockedThreads();
    if (threadIds != null && threadIds.length > 0) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter out = new PrintWriter(stringWriter);
        ThreadInfo[] infos = threadBean.getThreadInfo(threadIds, true, true);
        for (ThreadInfo ti : infos) {
            printThreadInfo(ti, out);
            printLockInfo(ti.getLockedSynchronizers(), out);
            out.println();
        }
        out.close();
        return stringWriter.toString();
    } else {
        return null;
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 3 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project hadoop by apache.

the class GenericTestUtils method anyThreadMatching.

/**
   * Determine if there are any threads whose name matches the regex.
   * @param pattern a Pattern object used to match thread names
   * @return true if there is any thread that matches the pattern
   */
public static boolean anyThreadMatching(Pattern pattern) {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
    for (ThreadInfo info : infos) {
        if (info == null)
            continue;
        if (pattern.matcher(info.getThreadName()).matches()) {
            return true;
        }
    }
    return false;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Example 4 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project hbase by apache.

the class GenericTestUtils method assertNoThreadsMatching.

/**
   * Assert that there are no threads running whose name matches the
   * given regular expression.
   * @param regex the regex to match against
   */
public static void assertNoThreadsMatching(String regex) {
    Pattern pattern = Pattern.compile(regex);
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
    for (ThreadInfo info : infos) {
        if (info == null)
            continue;
        if (pattern.matcher(info.getThreadName()).matches()) {
            Assert.fail("Leaked thread: " + info + "\n" + Joiner.on("\n").join(info.getStackTrace()));
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Example 5 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project hbase by apache.

the class TimedOutTestsListener method buildDeadlockInfo.

static String buildDeadlockInfo() {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long[] threadIds = threadBean.findMonitorDeadlockedThreads();
    if (threadIds != null && threadIds.length > 0) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter out = new PrintWriter(stringWriter);
        ThreadInfo[] infos = threadBean.getThreadInfo(threadIds, true, true);
        for (ThreadInfo ti : infos) {
            printThreadInfo(ti, out);
            printLockInfo(ti.getLockedSynchronizers(), out);
            out.println();
        }
        out.close();
        return stringWriter.toString();
    } else {
        return null;
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Aggregations

ThreadMXBean (java.lang.management.ThreadMXBean)87 ThreadInfo (java.lang.management.ThreadInfo)43 HashMap (java.util.HashMap)8 MemoryMXBean (java.lang.management.MemoryMXBean)7 RuntimeMXBean (java.lang.management.RuntimeMXBean)7 IOException (java.io.IOException)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ArrayList (java.util.ArrayList)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)4 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)4 MemoryUsage (java.lang.management.MemoryUsage)4 Date (java.util.Date)4 MonitorInfo (java.lang.management.MonitorInfo)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)2 FileOutputStream (java.io.FileOutputStream)2