use of java.lang.management.ThreadMXBean in project geode by apache.
the class DeployedJarJUnitTest method testMultiThreadingDoesNotCauseDeadlock.
@Test
public void testMultiThreadingDoesNotCauseDeadlock() throws Exception {
// Add two JARs to the classpath
byte[] jarBytes = this.classBuilder.createJarFromName("JarClassLoaderJUnitA");
ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitA.jar", jarBytes);
jarBytes = this.classBuilder.createJarFromClassContent("com/jcljunit/JarClassLoaderJUnitB", "package com.jcljunit; public class JarClassLoaderJUnitB {}");
ClassPathLoader.getLatest().getJarDeployer().deploy("JarClassLoaderJUnitB.jar", jarBytes);
String[] classNames = new String[] { "JarClassLoaderJUnitA", "com.jcljunit.JarClassLoaderJUnitB", "NON-EXISTENT CLASS" };
final int threadCount = 10;
ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
for (int i = 0; i < threadCount; i++) {
executorService.submit(new ForNameExerciser(classNames));
}
executorService.shutdown();
Awaitility.await().atMost(60, TimeUnit.SECONDS).until(executorService::isTerminated);
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
long[] threadIds = threadMXBean.findDeadlockedThreads();
if (threadIds != null) {
StringBuilder deadLockTrace = new StringBuilder();
for (long threadId : threadIds) {
ThreadInfo threadInfo = threadMXBean.getThreadInfo(threadId, 100);
deadLockTrace.append(threadInfo.getThreadName()).append("\n");
for (StackTraceElement stackTraceElem : threadInfo.getStackTrace()) {
deadLockTrace.append("\t").append(stackTraceElem).append("\n");
}
}
System.out.println(deadLockTrace);
}
assertThat(threadIds).isNull();
}
use of java.lang.management.ThreadMXBean in project gerrit by GerritCodeReview.
the class GetSummary method getThreadSummary.
private ThreadSummaryInfo getThreadSummary() {
Runtime r = Runtime.getRuntime();
ThreadSummaryInfo threadInfo = new ThreadSummaryInfo();
threadInfo.cpus = r.availableProcessors();
threadInfo.threads = toInteger(ManagementFactory.getThreadMXBean().getThreadCount());
List<String> prefixes = Arrays.asList("H2", "HTTP", "IntraLineDiff", "ReceiveCommits", "SSH git-receive-pack", "SSH git-upload-pack", "SSH-Interactive-Worker", "SSH-Stream-Worker", "SshCommandStart", "sshd-SshServer");
String other = "Other";
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
threadInfo.counts = new HashMap<>();
for (long id : threadMXBean.getAllThreadIds()) {
ThreadInfo info = threadMXBean.getThreadInfo(id);
if (info == null) {
continue;
}
String name = info.getThreadName();
Thread.State state = info.getThreadState();
String group = other;
for (String p : prefixes) {
if (name.startsWith(p)) {
group = p;
break;
}
}
Map<Thread.State, Integer> counts = threadInfo.counts.get(group);
if (counts == null) {
counts = new HashMap<>();
threadInfo.counts.put(group, counts);
}
Integer c = counts.get(state);
counts.put(state, c != null ? c + 1 : 1);
}
return threadInfo;
}
use of java.lang.management.ThreadMXBean 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.ThreadMXBean 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.ThreadMXBean 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;
}
}
Aggregations