use of java.lang.management.MonitorInfo in project indy by Commonjava.
the class ThreadDumper method dumpThreads.
public static void dumpThreads() {
StringBuilder sb = new StringBuilder();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
Stream.of(threadInfos).forEachOrdered((ti) -> {
if (sb.length() > 0) {
sb.append("\n\n");
}
sb.append(ti.getThreadName()).append("\n State: ").append(ti.getThreadState()).append("\n Lock Info: ").append(ti.getLockInfo()).append("\n Monitors:");
MonitorInfo[] monitors = ti.getLockedMonitors();
if (monitors == null || monitors.length < 1) {
sb.append(" -NONE-");
} else {
sb.append("\n - ").append(join(monitors, "\n - "));
}
sb.append("\n Trace:\n ").append(join(ti.getStackTrace(), "\n "));
});
System.out.println(sb);
}
use of java.lang.management.MonitorInfo in project indy by Commonjava.
the class DiagnosticsManager method getThreadDumpString.
public String getThreadDumpString() {
StringBuilder sb = new StringBuilder();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
Stream.of(threadInfos).forEachOrdered((ti) -> {
if (sb.length() > 0) {
sb.append("\n\n");
}
sb.append(ti.getThreadName()).append("\n State: ").append(ti.getThreadState()).append("\n Lock Info: ").append(ti.getLockInfo()).append("\n Monitors:");
MonitorInfo[] monitors = ti.getLockedMonitors();
if (monitors == null || monitors.length < 1) {
sb.append(" -NONE-");
} else {
sb.append("\n - ").append(join(monitors, "\n - "));
}
sb.append("\n Trace:\n ").append(join(ti.getStackTrace(), "\n "));
});
return sb.toString();
}
use of java.lang.management.MonitorInfo in project jdk8u_jdk by JetBrains.
the class ThreadInfoCompositeData method lockedMonitors.
public MonitorInfo[] lockedMonitors() {
CompositeData[] lockedMonitorsData = (CompositeData[]) cdata.get(LOCKED_MONITORS);
// The LockedMonitors item cannot be null, but if it is we will get
// a NullPointerException when we ask for its length.
MonitorInfo[] monitors = new MonitorInfo[lockedMonitorsData.length];
for (int i = 0; i < lockedMonitorsData.length; i++) {
CompositeData cdi = lockedMonitorsData[i];
monitors[i] = MonitorInfo.from(cdi);
}
return monitors;
}
use of java.lang.management.MonitorInfo in project jdk8u_jdk by JetBrains.
the class ThreadInfoCompositeData method getCompositeData.
protected CompositeData getCompositeData() {
// Convert StackTraceElement[] to CompositeData[]
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
CompositeData[] stackTraceData = new CompositeData[stackTrace.length];
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i];
stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
}
// Convert MonitorInfo[] and LockInfo[] to CompositeData[]
CompositeData lockInfoData = LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
// Convert LockInfo[] and MonitorInfo[] to CompositeData[]
LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
CompositeData[] lockedSyncsData = new CompositeData[lockedSyncs.length];
for (int i = 0; i < lockedSyncs.length; i++) {
LockInfo li = lockedSyncs[i];
lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
}
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
CompositeData[] lockedMonitorsData = new CompositeData[lockedMonitors.length];
for (int i = 0; i < lockedMonitors.length; i++) {
MonitorInfo mi = lockedMonitors[i];
lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
}
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
// threadInfoItemNames!
final Object[] threadInfoItemValues = { new Long(threadInfo.getThreadId()), threadInfo.getThreadName(), threadInfo.getThreadState().name(), new Long(threadInfo.getBlockedTime()), new Long(threadInfo.getBlockedCount()), new Long(threadInfo.getWaitedTime()), new Long(threadInfo.getWaitedCount()), lockInfoData, threadInfo.getLockName(), new Long(threadInfo.getLockOwnerId()), threadInfo.getLockOwnerName(), stackTraceData, new Boolean(threadInfo.isSuspended()), new Boolean(threadInfo.isInNative()), lockedMonitorsData, lockedSyncsData };
try {
return new CompositeDataSupport(threadInfoCompositeType, threadInfoItemNames, threadInfoItemValues);
} catch (OpenDataException e) {
// Should never reach here
throw new AssertionError(e);
}
}
use of java.lang.management.MonitorInfo in project dubbo by alibaba.
the class JVMUtil method getThreadDumpString.
private static String getThreadDumpString(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;
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
for (; i < stackTrace.length && i < 32; i++) {
StackTraceElement ste = stackTrace[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 : lockedMonitors) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
if (i < stackTrace.length) {
sb.append("\t...");
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();
}
Aggregations