Search in sources :

Example 81 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.

the class ThreadLists method main.

public static void main(String[] args) {
    // get top-level thread group
    ThreadGroup top = Thread.currentThread().getThreadGroup();
    ThreadGroup parent;
    do {
        parent = top.getParent();
        if (parent != null)
            top = parent;
    } while (parent != null);
    // get the thread count
    int activeCount = top.activeCount();
    Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    int threadCount = threadBean.getThreadCount();
    long[] threadIds = threadBean.getAllThreadIds();
    System.out.println("ThreadGroup: " + activeCount + " active thread(s)");
    System.out.println("Thread: " + stackTraces.size() + " stack trace(s) returned");
    System.out.println("ThreadMXBean: " + threadCount + " live threads(s)");
    System.out.println("ThreadMXBean: " + threadIds.length + " thread Id(s)");
    // check results are consistent
    boolean failed = false;
    if (activeCount != stackTraces.size())
        failed = true;
    if (activeCount != threadCount)
        failed = true;
    if (activeCount != threadIds.length)
        failed = true;
    if (failed) {
        throw new RuntimeException("inconsistent results");
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean)

Example 82 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.

the class SharedSynchronizer method main.

public static void main(String[] args) throws Exception {
    MyThread t = new MyThread();
    t.setDaemon(true);
    t.start();
    ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
    if (!tmbean.isSynchronizerUsageSupported()) {
        System.out.println("Monitoring of synchronizer usage not supported");
        return;
    }
    long[] result = tmbean.findDeadlockedThreads();
    if (result != null) {
        throw new RuntimeException("TEST FAILED: result should be null");
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean)

Example 83 with ThreadMXBean

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

the class ThreadDumpProvider method writeDump.

@Override
protected void writeDump(OutputStreamWriter outputStream) throws Exception {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    outputStream.write("Number of threads: " + threadMXBean.getThreadCount() + "\n");
    for (ThreadInfo threadInfo : threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), Integer.MAX_VALUE)) {
        outputStream.write(getDumpThreadString(threadInfo) + "\n\n");
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Example 84 with ThreadMXBean

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

the class EnvironmentDumpProvider method dumpThreadsInformation.

private void dumpThreadsInformation(final PrintWriter outPW) {
    final ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
    if (null == mxBean) {
        return;
    }
    outPW.println("Threads:");
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "live", formatLong(mxBean.getThreadCount())).println();
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "daemon", formatLong(mxBean.getDaemonThreadCount())).println();
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "peak", formatLong(mxBean.getPeakThreadCount())).println();
    outPW.printf(INDENT_KEY_VALUE_FORMAT, "total", formatLong(mxBean.getTotalStartedThreadCount())).println();
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean)

Example 85 with ThreadMXBean

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

the class GetNodeDetailsJSONWork method getCCDetails.

private ObjectNode getCCDetails() {
    ObjectNode o = om.createObjectNode();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    List<GarbageCollectorMXBean> gcMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    OperatingSystemMXBean osMXBean = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    if (includeConfig) {
        o.put("os_name", osMXBean.getName());
        o.put("arch", osMXBean.getArch());
        o.put("os_version", osMXBean.getVersion());
        o.put("num_processors", osMXBean.getAvailableProcessors());
        o.put("vm_name", runtimeMXBean.getVmName());
        o.put("vm_version", runtimeMXBean.getVmVersion());
        o.put("vm_vendor", runtimeMXBean.getVmVendor());
        o.putPOJO("classpath", runtimeMXBean.getClassPath().split(File.pathSeparator));
        o.putPOJO("library_path", runtimeMXBean.getLibraryPath().split(File.pathSeparator));
        o.putPOJO("boot_classpath", runtimeMXBean.getBootClassPath().split(File.pathSeparator));
        o.putPOJO("input_arguments", runtimeMXBean.getInputArguments());
        o.putPOJO("system_properties", runtimeMXBean.getSystemProperties());
        o.put("pid", PidHelper.getPid());
    }
    if (includeStats) {
        MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage();
        MemoryUsage nonheapUsage = memoryMXBean.getNonHeapMemoryUsage();
        List<ObjectNode> gcs = new ArrayList<>();
        for (GarbageCollectorMXBean gcMXBean : gcMXBeans) {
            ObjectNode gc = om.createObjectNode();
            gc.put("name", gcMXBean.getName());
            gc.put("collection-time", gcMXBean.getCollectionTime());
            gc.put("collection-count", gcMXBean.getCollectionCount());
            gcs.add(gc);
        }
        o.putPOJO("gcs", gcs);
        o.put("date", new Date().toString());
        o.put("heap_init_size", heapUsage.getInit());
        o.put("heap_used_size", heapUsage.getUsed());
        o.put("heap_committed_size", heapUsage.getCommitted());
        o.put("heap_max_size", heapUsage.getMax());
        o.put("nonheap_init_size", nonheapUsage.getInit());
        o.put("nonheap_used_size", nonheapUsage.getUsed());
        o.put("nonheap_committed_size", nonheapUsage.getCommitted());
        o.put("nonheap_max_size", nonheapUsage.getMax());
        o.put("thread_count", threadMXBean.getThreadCount());
        o.put("peak_thread_count", threadMXBean.getPeakThreadCount());
        o.put("started_thread_count", threadMXBean.getTotalStartedThreadCount());
        o.put("system_load_average", osMXBean.getSystemLoadAverage());
    }
    return o;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MemoryMXBean(java.lang.management.MemoryMXBean) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GarbageCollectorMXBean(java.lang.management.GarbageCollectorMXBean) ArrayList(java.util.ArrayList) RuntimeMXBean(java.lang.management.RuntimeMXBean) MemoryUsage(java.lang.management.MemoryUsage) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Date(java.util.Date)

Aggregations

ThreadMXBean (java.lang.management.ThreadMXBean)105 ThreadInfo (java.lang.management.ThreadInfo)56 HashMap (java.util.HashMap)9 RuntimeMXBean (java.lang.management.RuntimeMXBean)8 MemoryMXBean (java.lang.management.MemoryMXBean)7 IOException (java.io.IOException)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)4 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)4 MemoryUsage (java.lang.management.MemoryUsage)4 HealthCheckResultEntry (fish.payara.notification.healthcheck.HealthCheckResultEntry)3 HealthCheckResult (fish.payara.nucleus.healthcheck.HealthCheckResult)3 LockInfo (java.lang.management.LockInfo)3 ManagementFactory (java.lang.management.ManagementFactory)3 MonitorInfo (java.lang.management.MonitorInfo)3