use of java.lang.management.MonitorInfo in project com.revolsys.open by revolsys.
the class DeadlockLogger method toString.
private Object toString(final ThreadInfo threadInfo) {
final String threadName = threadInfo.getThreadName();
final long threadId = threadInfo.getThreadId();
final State threadState = threadInfo.getThreadState();
final StringBuilder sb = new StringBuilder("\"" + threadName + "\"" + " Id=" + threadId + " " + threadState);
final String lockName = threadInfo.getLockName();
if (lockName != null) {
sb.append(" on " + lockName);
}
final String lockOwnerName = threadInfo.getLockOwnerName();
if (lockOwnerName != null) {
final long lockOwnerId = threadInfo.getLockOwnerId();
sb.append(" owned by \"" + lockOwnerName + "\" Id=" + lockOwnerId);
}
if (threadInfo.isSuspended()) {
sb.append(" (suspended)");
}
if (threadInfo.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
final StackTraceElement[] stackTrace = threadInfo.getStackTrace();
int i = 0;
for (; i < stackTrace.length && i < 500; i++) {
final StackTraceElement ste = stackTrace[i];
sb.append("\tat " + ste.toString());
sb.append('\n');
final LockInfo lockInfo = threadInfo.getLockInfo();
if (i == 0 && lockInfo != null) {
final Thread.State ts = threadState;
switch(ts) {
case BLOCKED:
sb.append("\t- blocked on " + lockInfo);
sb.append('\n');
break;
case WAITING:
sb.append("\t- waiting on " + lockInfo);
sb.append('\n');
break;
case TIMED_WAITING:
sb.append("\t- waiting on " + lockInfo);
sb.append('\n');
break;
default:
}
}
final MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
for (final MonitorInfo mi : lockedMonitors) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
if (i < stackTrace.length) {
sb.append("\t...");
sb.append('\n');
}
final LockInfo[] locks = threadInfo.getLockedSynchronizers();
if (locks.length > 0) {
sb.append("\n\tNumber of locked synchronizers = " + locks.length);
sb.append('\n');
for (final LockInfo li : locks) {
sb.append("\t- " + li);
sb.append('\n');
}
}
sb.append('\n');
return sb.toString();
}
use of java.lang.management.MonitorInfo in project h2database by h2database.
the class AbbaLockingDetector method generateOrdering.
/**
* We cannot simply call getLockedMonitors because it is not guaranteed to
* return the locks in the correct order.
*/
private static void generateOrdering(final List<String> lockOrder, ThreadInfo info) {
final MonitorInfo[] lockedMonitors = info.getLockedMonitors();
Arrays.sort(lockedMonitors, new Comparator<MonitorInfo>() {
@Override
public int compare(MonitorInfo a, MonitorInfo b) {
return b.getLockedStackDepth() - a.getLockedStackDepth();
}
});
for (MonitorInfo mi : lockedMonitors) {
String lockName = getObjectName(mi);
if (lockName.equals("sun.misc.Launcher$AppClassLoader")) {
// ignore, it shows up everywhere
continue;
}
// succession - Java locks are recursive.
if (!lockOrder.contains(lockName)) {
lockOrder.add(lockName);
}
}
}
use of java.lang.management.MonitorInfo in project hudson-2.x by hudson.
the class Functions method dumpThreadInfo.
// ThreadInfo.toString() truncates the stack trace by first 8, so needed my own version
@IgnoreJRERequirement
public static String dumpThreadInfo(ThreadInfo ti, ThreadGroupMap map) {
String grp = map.getThreadGroup(ti);
StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " Group=" + (grp != null ? grp : "?") + " " + ti.getThreadState());
if (ti.getLockName() != null) {
sb.append(" on " + ti.getLockName());
}
if (ti.getLockOwnerName() != null) {
sb.append(" owned by \"" + ti.getLockOwnerName() + "\" Id=" + ti.getLockOwnerId());
}
if (ti.isSuspended()) {
sb.append(" (suspended)");
}
if (ti.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
StackTraceElement[] stackTrace = ti.getStackTrace();
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i];
sb.append("\tat " + ste.toString());
sb.append('\n');
if (i == 0 && ti.getLockInfo() != null) {
Thread.State ts = ti.getThreadState();
switch(ts) {
case BLOCKED:
sb.append("\t- blocked on " + ti.getLockInfo());
sb.append('\n');
break;
case WAITING:
sb.append("\t- waiting on " + ti.getLockInfo());
sb.append('\n');
break;
case TIMED_WAITING:
sb.append("\t- waiting on " + ti.getLockInfo());
sb.append('\n');
break;
default:
}
}
for (MonitorInfo mi : ti.getLockedMonitors()) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
LockInfo[] locks = ti.getLockedSynchronizers();
if (locks.length > 0) {
sb.append("\n\tNumber of locked synchronizers = " + locks.length);
sb.append('\n');
for (LockInfo li : locks) {
sb.append("\t- " + li);
sb.append('\n');
}
}
sb.append('\n');
return sb.toString();
}
use of java.lang.management.MonitorInfo in project indy by Commonjava.
the class ThreadDumper method dumpThreads.
public static void dumpThreads() {
StringBuilder sb = new StringBuilder();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
Stream.of(threadInfos).forEachOrdered((ti) -> {
if (sb.length() > 0) {
sb.append("\n\n");
}
sb.append(ti.getThreadName()).append("\n State: ").append(ti.getThreadState()).append("\n Lock Info: ").append(ti.getLockInfo()).append("\n Monitors:");
MonitorInfo[] monitors = ti.getLockedMonitors();
if (monitors == null || monitors.length < 1) {
sb.append(" -NONE-");
} else {
sb.append("\n - ").append(join(monitors, "\n - "));
}
sb.append("\n Trace:\n ").append(join(ti.getStackTrace(), "\n "));
});
System.out.println(sb);
}
use of java.lang.management.MonitorInfo in project indy by Commonjava.
the class ThreadDumper method dumpThreads.
public static void dumpThreads() {
StringBuilder sb = new StringBuilder();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
Stream.of(threadInfos).forEachOrdered((ti) -> {
if (sb.length() > 0) {
sb.append("\n\n");
}
sb.append(ti.getThreadName()).append("\n State: ").append(ti.getThreadState()).append("\n Lock Info: ").append(ti.getLockInfo()).append("\n Monitors:");
MonitorInfo[] monitors = ti.getLockedMonitors();
if (monitors == null || monitors.length < 1) {
sb.append(" -NONE-");
} else {
sb.append("\n - ").append(join(monitors, "\n - "));
}
sb.append("\n Trace:\n ").append(join(ti.getStackTrace(), "\n "));
});
System.out.println(sb);
}
Aggregations