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;
}
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);
}
}
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();
}
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;
}
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);
}
Aggregations