use of java.lang.management.LockInfo 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.LockInfo 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.LockInfo in project jdk8u_jdk by JetBrains.
the class ThreadMonitor method printLockInfo.
private void printLockInfo(LockInfo[] locks) {
System.out.println(INDENT + "Locked synchronizers: count = " + locks.length);
for (LockInfo li : locks) {
System.out.println(INDENT + " - " + li);
}
System.out.println();
}
use of java.lang.management.LockInfo 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.LockInfo in project jdk8u_jdk by JetBrains.
the class ThreadInfoCompositeData method lockedSynchronizers.
public LockInfo[] lockedSynchronizers() {
CompositeData[] lockedSyncsData = (CompositeData[]) cdata.get(LOCKED_SYNCS);
// The LockedSynchronizers item cannot be null, but if it is we will
// get a NullPointerException when we ask for its length.
LockInfo[] locks = new LockInfo[lockedSyncsData.length];
for (int i = 0; i < lockedSyncsData.length; i++) {
CompositeData cdi = lockedSyncsData[i];
locks[i] = LockInfo.from(cdi);
}
return locks;
}
Aggregations