use of java.lang.management.LockInfo in project geode by apache.
the class DeadlockDetector method collectAllDependencies.
/**
* Collect all of the dependencies that exist between threads in this VM, using java management
* beans and the {@link DependencyMonitor}.
*
* Threads may depend on locks, or on other resources that are tracked by the
* {@link DependencyMonitor}.
*
* @param locality a name tag to stick on entities to help associate them with this JVM and
* distinguish them from entities from other jvms
*
* @return All of the dependencies between threads and locks or other resources on this VM.
*/
public static Set<Dependency> collectAllDependencies(Serializable locality) {
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
ThreadInfo[] infos = bean.dumpAllThreads(true, true);
Set<Dependency> results = new HashSet<Dependency>();
Map<Long, ThreadInfo> threadInfos = new HashMap<Long, ThreadInfo>();
for (ThreadInfo info : infos) {
// This can happen if the thread died.
if (info == null) {
continue;
}
for (LockInfo monitor : info.getLockedMonitors()) {
Dependency dependency = new Dependency(new LocalLockInfo(locality, monitor), new LocalThread(locality, info));
results.add(dependency);
}
for (LockInfo sync : info.getLockedSynchronizers()) {
Dependency dependency = new Dependency(new LocalLockInfo(locality, sync), new LocalThread(locality, info));
results.add(dependency);
}
LockInfo waitingFor = info.getLockInfo();
if (waitingFor != null) {
Dependency dependency = new Dependency(new LocalThread(locality, info), new LocalLockInfo(locality, waitingFor));
results.add(dependency);
}
threadInfos.put(info.getThreadId(), info);
}
Set<Dependency> monitoredDependencies = collectFromDependencyMonitor(bean, locality, threadInfos);
results.addAll(monitoredDependencies);
return results;
}
use of java.lang.management.LockInfo in project metrics by dropwizard.
the class ThreadDump method dump.
/**
* Dumps all of the threads' current information to an output stream.
*
* @param out an output stream
*/
public void dump(OutputStream out) {
final ThreadInfo[] threads = this.threadMXBean.dumpAllThreads(true, true);
final PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, UTF_8));
for (int ti = threads.length - 1; ti >= 0; ti--) {
final ThreadInfo t = threads[ti];
writer.printf("\"%s\" id=%d state=%s", t.getThreadName(), t.getThreadId(), t.getThreadState());
final LockInfo lock = t.getLockInfo();
if (lock != null && t.getThreadState() != Thread.State.BLOCKED) {
writer.printf("%n - waiting on <0x%08x> (a %s)", lock.getIdentityHashCode(), lock.getClassName());
writer.printf("%n - locked <0x%08x> (a %s)", lock.getIdentityHashCode(), lock.getClassName());
} else if (lock != null && t.getThreadState() == Thread.State.BLOCKED) {
writer.printf("%n - waiting to lock <0x%08x> (a %s)", lock.getIdentityHashCode(), lock.getClassName());
}
if (t.isSuspended()) {
writer.print(" (suspended)");
}
if (t.isInNative()) {
writer.print(" (running in native)");
}
writer.println();
if (t.getLockOwnerName() != null) {
writer.printf(" owned by %s id=%d%n", t.getLockOwnerName(), t.getLockOwnerId());
}
final StackTraceElement[] elements = t.getStackTrace();
final MonitorInfo[] monitors = t.getLockedMonitors();
for (int i = 0; i < elements.length; i++) {
final StackTraceElement element = elements[i];
writer.printf(" at %s%n", element);
for (int j = 1; j < monitors.length; j++) {
final MonitorInfo monitor = monitors[j];
if (monitor.getLockedStackDepth() == i) {
writer.printf(" - locked %s%n", monitor);
}
}
}
writer.println();
final LockInfo[] locks = t.getLockedSynchronizers();
if (locks.length > 0) {
writer.printf(" Locked synchronizers: count = %d%n", locks.length);
for (LockInfo l : locks) {
writer.printf(" - %s%n", l);
}
writer.println();
}
}
writer.println();
writer.flush();
}
use of java.lang.management.LockInfo in project knime-core by knime.
the class GUIDeadlockDetector method fillStackFromThread.
private static void fillStackFromThread(final ThreadInfo ti, final StringBuilder buf) {
buf.append("\"" + ti.getThreadName() + "\" Id=" + ti.getThreadId() + " " + ti.getThreadState());
if (ti.getLockName() != null) {
buf.append(" on " + ti.getLockName());
}
if (ti.getLockOwnerName() != null) {
buf.append(" owned by \"" + ti.getLockOwnerName() + "\" Id=" + ti.getLockOwnerId());
}
if (ti.isSuspended()) {
buf.append(" (suspended)");
}
if (ti.isInNative()) {
buf.append(" (in native)");
}
buf.append('\n');
int i = 0;
for (StackTraceElement ste : ti.getStackTrace()) {
buf.append("\tat " + ste.toString());
buf.append('\n');
if ((i == 0) && (ti.getLockInfo() != null)) {
Thread.State ts = ti.getThreadState();
switch(ts) {
case BLOCKED:
buf.append("\t- blocked on " + ti.getLockInfo());
buf.append('\n');
break;
case WAITING:
buf.append("\t- waiting on " + ti.getLockInfo());
buf.append('\n');
break;
case TIMED_WAITING:
buf.append("\t- waiting on " + ti.getLockInfo());
buf.append('\n');
break;
default:
}
}
for (MonitorInfo mi : ti.getLockedMonitors()) {
if (mi.getLockedStackDepth() == i) {
buf.append("\t- locked " + mi);
buf.append('\n');
}
}
i++;
}
LockInfo[] locks = ti.getLockedSynchronizers();
if (locks.length > 0) {
buf.append("\n\tNumber of locked synchronizers = " + locks.length);
buf.append('\n');
for (LockInfo li : locks) {
buf.append("\t- " + li);
buf.append('\n');
}
}
buf.append('\n');
}
use of java.lang.management.LockInfo in project parseq by linkedin.
the class ThreadDumper method dumpThreadInfoWithLocks.
private void dumpThreadInfoWithLocks(StringBuilder out) {
ThreadInfo[] tinfos = tmbean.dumpAllThreads(true, true);
for (ThreadInfo ti : tinfos) {
dumpThreadInfo(ti, out);
LockInfo[] syncs = ti.getLockedSynchronizers();
dumpLockInfo(syncs, out);
}
out.append("\n");
findDeadlock(out);
}
use of java.lang.management.LockInfo in project Mindroid.java by Himmele.
the class ConsoleService method addThreadInformation.
@SuppressWarnings("incomplete-switch")
private static void addThreadInformation(StringBuilder builder, ThreadInfo threadInfo) {
builder.append('"').append(threadInfo.getThreadName()).append('"').append(threadInfo.isDaemon() ? " daemon" : "").append(" prio=").append(threadInfo.getPriority()).append(" id=").append(threadInfo.getThreadId()).append(" ").append(threadInfo.getThreadState());
if (threadInfo.getLockName() != null) {
builder.append(" on ").append(threadInfo.getLockName());
}
if (threadInfo.getLockOwnerName() != null) {
builder.append(" owned by \"").append(threadInfo.getLockOwnerName()).append("\" id=").append(threadInfo.getLockOwnerId());
}
if (threadInfo.isSuspended()) {
builder.append(" (suspended)");
}
if (threadInfo.isInNative()) {
builder.append(" (in native)");
}
builder.append('\n');
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
for (int i = 0; i < stackTrace.length; ++i) {
StackTraceElement ste = stackTrace[i];
builder.append("\tat ").append(ste.toString());
builder.append('\n');
if (i == 0 && threadInfo.getLockInfo() != null) {
Thread.State ts = threadInfo.getThreadState();
switch(ts) {
case BLOCKED:
builder.append("\t- blocked on ").append(threadInfo.getLockInfo());
builder.append('\n');
break;
case WAITING:
case TIMED_WAITING:
builder.append("\t- waiting on ").append(threadInfo.getLockInfo());
builder.append('\n');
break;
}
}
for (MonitorInfo mi : lockedMonitors) {
if (mi.getLockedStackDepth() == i) {
builder.append("\t- locked ").append(mi);
builder.append('\n');
}
}
}
LockInfo[] locks = threadInfo.getLockedSynchronizers();
if (locks.length > 0) {
builder.append("\n\tLocked synchronizers count = ").append(locks.length);
builder.append('\n');
for (LockInfo li : locks) {
builder.append("\t- ").append(li);
builder.append('\n');
}
}
builder.append('\n');
}
Aggregations