Search in sources :

Example 66 with ThreadInfo

use of java.lang.management.ThreadInfo in project jvm-tools by aragozin.

the class ThreadDumpSampler method prime.

/**
	 * Find threads according to thread name filters and memorise their IDs.
	 * <br/>
	 * Optional method to avoid dump all threads at every collection.
	 */
public void prime() {
    ThreadInfo[] ti = threading.dumpAllThreads(false, false);
    long[] tids = new long[ti.length];
    int n = 0;
    for (ThreadInfo t : ti) {
        long tid = t.getThreadId();
        String name = t.getThreadName();
        if (threadFilter == null || threadFilter.matcher(name).matches()) {
            tids[n++] = tid;
        }
    }
    tids = Arrays.copyOf(tids, n);
    threadSet = tids;
}
Also used : ThreadInfo(java.lang.management.ThreadInfo)

Example 67 with ThreadInfo

use of java.lang.management.ThreadInfo in project jvm-tools by aragozin.

the class ThreadDumpSampler method collect.

public void collect(StackTraceWriter writer) throws IOException {
    long timestamp = System.currentTimeMillis();
    ThreadInfo[] dump;
    if (threadSet != null) {
        dump = compactThreads(threading.getThreadInfo(threadSet, Integer.MAX_VALUE));
    } else {
        dump = filterThreads(threading.dumpAllThreads(false, false));
    }
    long[] ids = new long[dump.length];
    for (int i = 0; i != dump.length; ++i) {
        ids[i] = dump[i].getThreadId();
    }
    for (CounterCollector cc : collectors) {
        try {
            cc.collect(ids);
        } catch (Exception e) {
        // ignore
        }
    }
    ThreadCapture ts = new ThreadCapture();
    for (ThreadInfo ti : dump) {
        ts.reset();
        ts.timestamp = timestamp;
        ts.copyFrom(ti);
        for (CounterCollector cc : collectors) {
            try {
                cc.fillIntoSnapshot(ts);
            } catch (Exception e) {
            // ignore
            }
        }
        writer.write(ts);
    }
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) IOException(java.io.IOException)

Example 68 with ThreadInfo

use of java.lang.management.ThreadInfo in project tomcat by apache.

the class Diagnostics method getThreadDump.

/**
     * Formats the thread dump for a list of threads.
     *
     * @param tinfos the ThreadInfo array describing the thread list
     * @return the formatted thread dump
     */
private static String getThreadDump(ThreadInfo[] tinfos) {
    StringBuilder sb = new StringBuilder();
    for (ThreadInfo tinfo : tinfos) {
        sb.append(getThreadDump(tinfo));
        sb.append(CRLF);
    }
    return sb.toString();
}
Also used : ThreadInfo(java.lang.management.ThreadInfo)

Example 69 with ThreadInfo

use of java.lang.management.ThreadInfo in project elasticsearch by elastic.

the class DeadlockAnalyzer method calculateCycleDeadlockChains.

private Set<LinkedHashSet<ThreadInfo>> calculateCycleDeadlockChains(Map<Long, ThreadInfo> threadInfoMap, Set<LinkedHashSet<ThreadInfo>> cycles) {
    ThreadInfo[] allThreads = threadBean.getThreadInfo(threadBean.getAllThreadIds());
    Set<LinkedHashSet<ThreadInfo>> deadlockChain = new HashSet<>();
    Set<Long> knownDeadlockedThreads = threadInfoMap.keySet();
    for (ThreadInfo threadInfo : allThreads) {
        Thread.State state = threadInfo.getThreadState();
        if (state == Thread.State.BLOCKED && !knownDeadlockedThreads.contains(threadInfo.getThreadId())) {
            for (LinkedHashSet<ThreadInfo> cycle : cycles) {
                if (cycle.contains(threadInfoMap.get(Long.valueOf(threadInfo.getLockOwnerId())))) {
                    LinkedHashSet<ThreadInfo> chain = new LinkedHashSet<>();
                    ThreadInfo node = threadInfo;
                    while (!chain.contains(node)) {
                        chain.add(node);
                        node = threadInfoMap.get(Long.valueOf(node.getLockOwnerId()));
                    }
                    deadlockChain.add(chain);
                }
            }
        }
    }
    return deadlockChain;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ThreadInfo(java.lang.management.ThreadInfo) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 70 with ThreadInfo

use of java.lang.management.ThreadInfo in project elasticsearch by elastic.

the class DeadlockAnalyzer method createThreadInfoMap.

private Map<Long, ThreadInfo> createThreadInfoMap(long[] threadIds) {
    ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadIds);
    Map<Long, ThreadInfo> threadInfoMap = new HashMap<>();
    for (ThreadInfo threadInfo : threadInfos) {
        threadInfoMap.put(threadInfo.getThreadId(), threadInfo);
    }
    return unmodifiableMap(threadInfoMap);
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) HashMap(java.util.HashMap)

Aggregations

ThreadInfo (java.lang.management.ThreadInfo)124 ThreadMXBean (java.lang.management.ThreadMXBean)56 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LockInfo (java.lang.management.LockInfo)6 MonitorInfo (java.lang.management.MonitorInfo)6 Test (org.junit.Test)5 Date (java.util.Date)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 FileOutputStream (java.io.FileOutputStream)3 PrintStream (java.io.PrintStream)3 PrintWriter (java.io.PrintWriter)3 Method (java.lang.reflect.Method)3 LinkedHashSet (java.util.LinkedHashSet)3 TreeMap (java.util.TreeMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 HealthCheckResultEntry (fish.payara.notification.healthcheck.HealthCheckResultEntry)2