use of java.lang.management.ThreadInfo in project jdk8u_jdk by JetBrains.
the class ConnectorStopDeadlockTest method waitForBlock.
// static MonitorInfo[] threadLocks(Thread t) {
// ThreadMXBean tm = ManagementFactory.getThreadMXBean();
// ThreadInfo[] tis = tm.getThreadInfo(new long[] {t.getId()}, true, true);
// if (tis[0] == null)
// return null;
// else
// return tis[0].getLockedMonitors();
// }
//
// static void showLocks(Thread t) {
// System.out.println("Locks for " + t.getName() + ":");
// MonitorInfo[] mis = threadLocks(t);
// if (mis == null)
// System.out.println(" (no longer exists)");
// else if (mis.length == 0)
// System.out.println(" (none)");
// else {
// for (MonitorInfo mi : mis)
// System.out.println(" " + mi);
// }
// }
// Wait until thread t blocks waiting for a lock held by the calling thread,
// or until it exits.
static void waitForBlock(Thread t) {
Thread currentThread = Thread.currentThread();
System.out.println("waiting for thread " + t.getName() + " to block " + "on a lock held by thread " + currentThread.getName());
ThreadMXBean tm = ManagementFactory.getThreadMXBean();
while (true) {
ThreadInfo ti = tm.getThreadInfo(t.getId());
if (ti == null) {
System.out.println(" thread has exited");
return;
}
if (ti.getLockOwnerId() == currentThread.getId()) {
System.out.println(" thread now blocked");
return;
}
Thread.yield();
}
}
use of java.lang.management.ThreadInfo in project symmetric-ds by JumpMind.
the class MonitorTypeCpu method getNotificationMessage.
protected String getNotificationMessage(long value, long threshold, long period) {
ThreadInfo[] infos = new ThreadInfo[TOP_THREADS];
long[] cpuUsages = new long[TOP_THREADS];
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
for (long threadId : threadBean.getAllThreadIds()) {
ThreadInfo info = threadBean.getThreadInfo(threadId);
if (info.getThreadState() != Thread.State.TERMINATED) {
rankTopUsage(infos, cpuUsages, info, threadBean.getThreadCpuTime(threadId));
}
}
String text = "CPU usage is at " + value;
for (int i = 0; i < infos.length; i++) {
text += "Top #" + (i + 1) + " CPU thread " + infos[i].getThreadId() + " is using " + (cpuUsages[i] / 1000000000f) + "s";
text += logStackTrace(threadBean.getThreadInfo(infos[i].getThreadId(), MAX_STACK_DEPTH));
}
return text;
}
use of java.lang.management.ThreadInfo in project symmetric-ds by JumpMind.
the class MonitorTypeMemory method getMessage.
public String getMessage(long value, long threshold, long period) {
long maxMemory = tenuredPool.getUsage().getMax();
long usedMemory = tenuredPool.getUsage().getUsed();
String text = "Memory threshold exceeded, " + usedMemory + " of " + maxMemory;
ThreadInfo[] infos = new ThreadInfo[TOP_THREADS];
long[] byteUsages = new long[TOP_THREADS];
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
for (long threadId : threadBean.getAllThreadIds()) {
ThreadInfo info = threadBean.getThreadInfo(threadId);
if (info.getThreadState() != Thread.State.TERMINATED) {
rankTopUsage(infos, byteUsages, info, getThreadAllocatedBytes(threadBean, threadId));
}
}
for (int i = 0; i < infos.length; i++) {
text += "Top #" + (i + 1) + " memory thread " + infos[i].getThreadId() + " is using " + String.format("%.1f", ((double) byteUsages[i] / 1048576f)) + "MB";
text += logStackTrace(threadBean.getThreadInfo(infos[i].getThreadId(), MAX_STACK_DEPTH));
}
return text;
}
use of java.lang.management.ThreadInfo in project symmetric-ds by JumpMind.
the class ProcessInfo method getThreadData.
public static ThreadData getThreadData(long threadId) {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
ThreadInfo info = threadBean.getThreadInfo(threadId, 100);
if (info != null) {
String threadName = info.getThreadName();
return new ThreadData(threadName, AppUtils.formatStackTrace(info.getStackTrace()));
} else {
return null;
}
}
use of java.lang.management.ThreadInfo 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();
}
Aggregations