use of java.lang.management.MonitorInfo in project nifi by apache.
the class ThreadUtils method createStackTrace.
public static String createStackTrace(final Thread thread, final ThreadInfo threadInfo, final long[] deadlockedThreadIds, final long[] monitorDeadlockThreadIds, final long activeMillis) {
final StringBuilder sb = new StringBuilder();
sb.append("\"").append(threadInfo.getThreadName()).append("\" Id=");
sb.append(threadInfo.getThreadId()).append(" ");
sb.append(threadInfo.getThreadState().toString()).append(" ");
switch(threadInfo.getThreadState()) {
case BLOCKED:
case TIMED_WAITING:
case WAITING:
sb.append(" on ");
sb.append(threadInfo.getLockInfo());
break;
default:
break;
}
if (threadInfo.isSuspended()) {
sb.append(" (suspended)");
}
if (threadInfo.isInNative()) {
sb.append(" (in native code)");
}
if (deadlockedThreadIds != null && deadlockedThreadIds.length > 0) {
for (final long id : deadlockedThreadIds) {
if (id == threadInfo.getThreadId()) {
sb.append(" ** DEADLOCKED THREAD **");
}
}
}
if (monitorDeadlockThreadIds != null && monitorDeadlockThreadIds.length > 0) {
for (final long id : monitorDeadlockThreadIds) {
if (id == threadInfo.getThreadId()) {
sb.append(" ** MONITOR-DEADLOCKED THREAD **");
}
}
}
final StackTraceElement[] stackTraces = threadInfo.getStackTrace();
for (final StackTraceElement element : stackTraces) {
sb.append("\n\tat ").append(element);
final MonitorInfo[] monitors = threadInfo.getLockedMonitors();
for (final MonitorInfo monitor : monitors) {
if (monitor.getLockedStackFrame().equals(element)) {
sb.append("\n\t- waiting on ").append(monitor);
}
}
}
final LockInfo[] lockInfos = threadInfo.getLockedSynchronizers();
if (lockInfos.length > 0) {
sb.append("\n\t");
sb.append("Number of Locked Synchronizers: ").append(lockInfos.length);
for (final LockInfo lockInfo : lockInfos) {
sb.append("\n\t- ").append(lockInfo.toString());
}
}
sb.append("\n");
return sb.toString();
}
use of java.lang.management.MonitorInfo in project support-core-plugin by jenkinsci.
the class ThreadDumps method printThreadInfo.
// TODO Functions.sortThreadsAndGetGroupMap + Functions.Functions.dumpThreadInfo not showing lock owners in some cases
/**
* Prints the {@link ThreadInfo} (because {@link ThreadInfo#toString()} caps out the stack trace at 8 frames)
*
* @param writer the writer to print to.
* @param t the thread to print
* @param mbean the {@link ThreadMXBean} to use.
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = { "VA_FORMAT_STRING_USES_NEWLINE" }, justification = "We don't want platform specific")
public static void printThreadInfo(PrintWriter writer, ThreadInfo t, ThreadMXBean mbean) {
long cpuPercentage;
try {
long cpuTime = mbean.getThreadCpuTime(t.getThreadId());
long threadUserTime = mbean.getThreadUserTime(t.getThreadId());
cpuPercentage = (cpuTime == 0) ? 0 : 100 * threadUserTime / cpuTime;
} catch (UnsupportedOperationException x) {
SupportLogFormatter.printStackTrace(x, writer);
cpuPercentage = 0;
}
writer.printf("\"%s\" id=%d (0x%x) state=%s cpu=%d%%", t.getThreadName(), t.getThreadId(), t.getThreadId(), t.getThreadState(), cpuPercentage);
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 (0x%x)\n", t.getLockOwnerName(), t.getLockOwnerId(), 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();
}
}
use of java.lang.management.MonitorInfo in project jdk8u_jdk by JetBrains.
the class ThreadMonitor method printMonitorInfo.
private void printMonitorInfo(ThreadInfo ti) {
MonitorInfo[] monitors = ti.getLockedMonitors();
System.out.println(INDENT + "Locked monitors: count = " + monitors.length);
for (MonitorInfo mi : monitors) {
System.out.println(INDENT + " - " + mi + " locked at ");
System.out.println(INDENT + " " + mi.getLockedStackDepth() + " " + mi.getLockedStackFrame());
}
}
use of java.lang.management.MonitorInfo in project jdk8u_jdk by JetBrains.
the class ThreadMonitor method printThreadInfo.
private void printThreadInfo(ThreadInfo ti) {
// print thread information
printThread(ti);
// print stack trace with locks
StackTraceElement[] stacktrace = ti.getStackTrace();
MonitorInfo[] monitors = ti.getLockedMonitors();
for (int i = 0; i < stacktrace.length; i++) {
StackTraceElement ste = stacktrace[i];
System.out.println(INDENT + "at " + ste.toString());
for (MonitorInfo mi : monitors) {
if (mi.getLockedStackDepth() == i) {
System.out.println(INDENT + " - locked " + mi);
}
}
}
System.out.println();
}
use of java.lang.management.MonitorInfo in project sling by apache.
the class ControlListener method printThread.
private void printThread(final Socket socket, final ThreadInfo thread) throws IOException {
writeLine(socket, String.format("-\"%s\" #%d", thread.getThreadName(), thread.getThreadId()));
writeLine(socket, String.format("- java.lang.Thread.State: %s", thread.getThreadState()));
final MonitorInfo[] monitors = thread.getLockedMonitors();
final StackTraceElement[] trace = thread.getStackTrace();
for (int i = 0; i < trace.length; i++) {
StackTraceElement ste = trace[i];
if (ste.isNativeMethod()) {
writeLine(socket, String.format("- at %s.%s(Native Method)", ste.getClassName(), ste.getMethodName()));
} else {
writeLine(socket, String.format("- at %s.%s(%s:%d)", ste.getClassName(), ste.getMethodName(), ste.getFileName(), ste.getLineNumber()));
}
if (i == 0 && thread.getLockInfo() != null) {
writeLine(socket, String.format("- - waiting on %s%s", formatLockInfo(thread.getLockInfo().getClassName(), thread.getLockInfo().getIdentityHashCode()), (thread.getLockOwnerId() >= 0) ? String.format(" owned by \"%s\" #%d", thread.getLockOwnerName(), thread.getLockOwnerId()) : ""));
}
for (MonitorInfo mi : monitors) {
if (i == mi.getLockedStackDepth()) {
writeLine(socket, String.format("- - locked %s", formatLockInfo(mi.getClassName(), mi.getIdentityHashCode())));
}
}
}
}
Aggregations