use of java.lang.management.ThreadInfo in project jgnash by ccavanaugh.
the class EventDispatchThreadHangMonitor method checkForDeadlock.
private static void checkForDeadlock() {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long[] threadIds = threadBean.findMonitorDeadlockedThreads();
if (threadIds == null) {
return;
}
Log.warn("deadlock detected involving the following threads:");
ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
for (ThreadInfo info : threadInfos) {
Log.warn("Thread #" + info.getThreadId() + " " + info.getThreadName() + " (" + info.getThreadState() + ") waiting on " + info.getLockName() + " held by " + info.getLockOwnerName() + stackTraceToString(info.getStackTrace()));
}
}
use of java.lang.management.ThreadInfo in project cdap by caskdata.
the class ReflectionUtils method printThreadInfo.
/**
* Print all of the thread's information and stack traces.
*
* @param stream the stream to
* @param title a string title for the stack trace
*/
public static synchronized void printThreadInfo(PrintWriter stream, String title) {
final int stackDepth = 20;
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, stackDepth);
if (info == null) {
stream.println(" Inactive");
continue;
}
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();
}
use of java.lang.management.ThreadInfo in project jdk8u_jdk by JetBrains.
the class ThreadMonitor method dumpThreadInfoWithLocks.
/**
* Prints the thread dump information with locks info to System.out.
*/
private void dumpThreadInfoWithLocks() {
System.out.println("Full Java thread dump with locks info");
ThreadInfo[] tinfos = tmbean.dumpAllThreads(true, true);
for (ThreadInfo ti : tinfos) {
printThreadInfo(ti);
LockInfo[] syncs = ti.getLockedSynchronizers();
printLockInfo(syncs);
}
System.out.println();
}
use of java.lang.management.ThreadInfo in project jdk8u_jdk by JetBrains.
the class JvmThreadInstanceTableMetaImpl method getJvmThreadInstance.
private JvmThreadInstanceEntryImpl getJvmThreadInstance(Object userData, SnmpOid oid) {
JvmThreadInstanceEntryImpl cached = null;
String entryTag = null;
Map<Object, Object> map = null;
final boolean dbg = log.isDebugOn();
if (userData instanceof Map) {
map = Util.cast(userData);
// We're going to use this name to store/retrieve the entry in
// the request contextual cache.
//
// Revisit: Probably better programming to put all these strings
// in some interface.
//
entryTag = "JvmThreadInstanceTable.entry." + oid.toString();
cached = (JvmThreadInstanceEntryImpl) map.get(entryTag);
}
//
if (cached != null) {
if (dbg)
log.debug("*** getJvmThreadInstance", "Entry found in cache: " + entryTag);
return cached;
}
if (dbg)
log.debug("*** getJvmThreadInstance", "Entry [" + oid + "] is not in cache");
// Entry not in cache. We will create one if needed.
//
ThreadInfo info = null;
try {
info = getThreadInfo(oid);
} catch (RuntimeException r) {
log.trace("*** getJvmThreadInstance", "Failed to get thread info for rowOid: " + oid);
log.debug("*** getJvmThreadInstance", r);
}
//
if (info == null) {
if (dbg)
log.debug("*** getJvmThreadInstance", "No entry by that oid [" + oid + "]");
return null;
}
cached = new JvmThreadInstanceEntryImpl(info, oid.toByte());
if (map != null)
map.put(entryTag, cached);
if (dbg)
log.debug("*** getJvmThreadInstance", "Entry created for Thread OID [" + oid + "]");
return cached;
}
use of java.lang.management.ThreadInfo in project processdash by dtuma.
the class ThreadMonitor method dumpThreadInfo.
/**
* Prints the thread dump information to System.out.
*/
public void dumpThreadInfo() {
System.out.println("Full Java thread dump");
long[] tids = tmbean.getAllThreadIds();
ThreadInfo[] tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
for (ThreadInfo ti : tinfos) {
printThreadInfo(ti);
}
}
Aggregations