use of java.lang.management.LockInfo in project activemq-artemis by apache.
the class ThreadDumpUtil method threadInfoToString.
private static String threadInfoToString(ThreadInfo threadInfo) {
StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState());
if (threadInfo.getLockName() != null) {
sb.append(" on " + threadInfo.getLockName());
}
if (threadInfo.getLockOwnerName() != null) {
sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId());
}
if (threadInfo.isSuspended()) {
sb.append(" (suspended)");
}
if (threadInfo.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
int i = 0;
for (; i < threadInfo.getStackTrace().length; i++) {
StackTraceElement ste = threadInfo.getStackTrace()[i];
sb.append("\tat " + ste.toString());
sb.append('\n');
if (i == 0 && threadInfo.getLockInfo() != null) {
Thread.State ts = threadInfo.getThreadState();
switch(ts) {
case BLOCKED:
sb.append("\t- blocked on " + threadInfo.getLockInfo());
sb.append('\n');
break;
case WAITING:
sb.append("\t- waiting on " + threadInfo.getLockInfo());
sb.append('\n');
break;
case TIMED_WAITING:
sb.append("\t- waiting on " + threadInfo.getLockInfo());
sb.append('\n');
break;
default:
}
}
for (MonitorInfo mi : threadInfo.getLockedMonitors()) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
LockInfo[] locks = threadInfo.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.LockInfo in project tomcat70 by apache.
the class Diagnostics method getThreadDump.
/**
* Formats the thread dump for one thread.
*
* @param ti the ThreadInfo describing the thread
* @return the formatted thread dump
*/
private static String getThreadDump(ThreadInfo ti) {
StringBuilder sb = new StringBuilder(getThreadDumpHeader(ti));
for (LockInfo li : ti.getLockedSynchronizers()) {
sb.append(INDENT2 + "locks " + li.toString() + CRLF);
}
boolean start = true;
StackTraceElement[] stes = ti.getStackTrace();
Object[] monitorDepths = new Object[stes.length];
MonitorInfo[] mis = ti.getLockedMonitors();
for (int i = 0; i < mis.length; i++) {
monitorDepths[mis[i].getLockedStackDepth()] = mis[i];
}
for (int i = 0; i < stes.length; i++) {
StackTraceElement ste = stes[i];
sb.append(INDENT2 + "at " + ste.toString() + CRLF);
if (start) {
if (ti.getLockName() != null) {
sb.append(INDENT2 + "- waiting on (a " + ti.getLockName() + ")");
if (ti.getLockOwnerName() != null) {
sb.append(" owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId());
}
sb.append(CRLF);
}
start = false;
}
if (monitorDepths[i] != null) {
MonitorInfo mi = (MonitorInfo) monitorDepths[i];
sb.append(INDENT2 + "- locked (a " + mi.toString() + ")" + " index " + mi.getLockedStackDepth() + " frame " + mi.getLockedStackFrame().toString());
sb.append(CRLF);
}
}
return sb.toString();
}
use of java.lang.management.LockInfo in project kafka by apache.
the class SynchronizationTest method threadInfoToString.
private static String threadInfoToString(ThreadInfo info) {
StringBuilder sb = new StringBuilder("\"" + info.getThreadName() + "\"" + " Id=" + info.getThreadId() + " " + info.getThreadState());
if (info.getLockName() != null) {
sb.append(" on " + info.getLockName());
}
if (info.getLockOwnerName() != null) {
sb.append(" owned by \"" + info.getLockOwnerName() + "\" Id=" + info.getLockOwnerId());
}
if (info.isSuspended()) {
sb.append(" (suspended)");
}
if (info.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
// this has been refactored for checkstyle
printStacktrace(info, sb);
LockInfo[] locks = info.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.LockInfo in project pinpoint by naver.
the class DeadlockMonitorTask method createThreadDump.
/**
* refer to java.lang.management.ThreadInfo.toString {@link ThreadInfo}
* To find loadClass cause. MAX_FRAME is too short , the length.
*/
private String createThreadDump(ThreadInfo threadInfo) {
StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState());
if (threadInfo.getLockName() != null) {
sb.append(" on " + threadInfo.getLockName());
}
if (threadInfo.getLockOwnerName() != null) {
sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId());
}
if (threadInfo.isSuspended()) {
sb.append(" (suspended)");
}
if (threadInfo.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i];
sb.append("\tat " + ste.toString());
sb.append('\n');
if (i == 0 && threadInfo.getLockInfo() != null) {
LockInfo lockInfo = threadInfo.getLockInfo();
Thread.State ts = threadInfo.getThreadState();
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:
}
}
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
for (MonitorInfo mi : lockedMonitors) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
LockInfo[] locks = threadInfo.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.LockInfo in project spring-boot by spring-projects.
the class PlainTextThreadDumpFormatter method writeLockedOwnableSynchronizers.
private void writeLockedOwnableSynchronizers(PrintWriter writer, ThreadInfo info) {
writer.println(" Locked ownable synchronizers:");
LockInfo[] lockedSynchronizers = info.getLockedSynchronizers();
if (lockedSynchronizers == null || lockedSynchronizers.length == 0) {
writer.println("\t- None");
} else {
for (LockInfo lockedSynchronizer : lockedSynchronizers) {
writer.printf("\t- Locked %s%n", format(lockedSynchronizer));
}
}
}
Aggregations