use of java.lang.management.MonitorInfo 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.MonitorInfo 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.MonitorInfo in project parseq by linkedin.
the class ThreadDumper method dumpThreadInfo.
private void dumpThreadInfo(ThreadInfo ti, StringBuilder out) {
// dump thread information
dumpThread(ti, out);
// dump stack trace with locks
StackTraceElement[] stacktrace = ti.getStackTrace();
MonitorInfo[] monitors = ti.getLockedMonitors();
for (int i = 0; i < stacktrace.length; i++) {
StackTraceElement ste = stacktrace[i];
out.append(INDENT).append("at ").append(ste).append("\n");
for (MonitorInfo mi : monitors) {
if (mi.getLockedStackDepth() == i) {
out.append(INDENT).append(" - locked ").append(mi).append("\n");
}
}
}
out.append("\n");
}
use of java.lang.management.MonitorInfo 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');
}
use of java.lang.management.MonitorInfo in project JikesRVM by JikesRVM.
the class VMThreadMXBeanImpl method getThreadInfoForId.
/**
* Returns a {@link java.lang.management.ThreadInfo}
* object for the given thread id with a stack trace to
* the given depth (0 for empty, Integer.MAX_VALUE for
* full).
*
* @param id the id of the thread whose info should be returned.
* @param maxDepth the depth of the stack trace.
* @return a {@link java.lang.management.ThreadInfo} instance.
*/
static ThreadInfo getThreadInfoForId(long id, int maxDepth) {
Thread thread = getThreadForId(id);
Constructor<ThreadInfo> cons = null;
try {
// ensure class is at least resolved
Class.forName("java.lang.management.ThreadInfo");
cons = ThreadInfo.class.getDeclaredConstructor(Long.TYPE, String.class, Thread.State.class, Long.TYPE, Long.TYPE, String.class, Long.TYPE, String.class, Long.TYPE, Long.TYPE, Boolean.TYPE, Boolean.TYPE, StackTraceElement[].class, MonitorInfo[].class, LockInfo[].class);
cons.setAccessible(true);
RVMThread rvmThread = JikesRVMSupport.getThread(thread);
// TODO number of times blocked for Java monitors
long blockedCount = 0;
// TODO total time blocked for Java monitors
long blockedTime = 0;
long waitingCount = JMXSupport.getWaitingCount(rvmThread);
long waitingTime = JMXSupport.getWaitingTime(rvmThread);
boolean inNative = JMXSupport.isInNative(rvmThread);
boolean suspended = JMXSupport.isSuspended(rvmThread);
StackTraceElement[] stackTrace;
if (maxDepth == 0) {
stackTrace = null;
} else {
stackTrace = JMXSupport.getStackTraceForThread(rvmThread);
int newMax = Math.min(stackTrace.length, maxDepth);
StackTraceElement[] reducedStackTrace = new StackTraceElement[newMax];
int srcPos = stackTrace.length - newMax;
System.arraycopy(stackTrace, srcPos, reducedStackTrace, 0, newMax);
stackTrace = reducedStackTrace;
}
MonitorInfo[] emptyMonitorInfo = new MonitorInfo[0];
LockInfo[] emptyLockInfo = new LockInfo[0];
return cons.newInstance(id, thread.getName(), thread.getState(), blockedCount, blockedTime, null, -1, null, waitingCount, waitingTime, inNative, suspended, stackTrace, emptyMonitorInfo, emptyLockInfo);
} catch (NoSuchMethodException e) {
throw (Error) new InternalError("Couldn't get ThreadInfo constructor").initCause(e);
} catch (InstantiationException e) {
throw (Error) new InternalError("Couldn't create ThreadInfo").initCause(e);
} catch (IllegalAccessException e) {
throw (Error) new InternalError("Couldn't access ThreadInfo").initCause(e);
} catch (InvocationTargetException e) {
throw (Error) new InternalError("ThreadInfo's constructor threw an exception").initCause(e);
} catch (ClassNotFoundException e) {
throw (Error) new InternalError("Problem resolving ThreadInfo").initCause(e);
}
}
Aggregations