use of java.lang.management.ThreadInfo in project orientdb by orientechnologies.
the class OAbstractProfiler method threadDump.
@Override
public String threadDump() {
final StringBuilder dump = new StringBuilder();
dump.append("THREAD DUMP\n");
final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
for (ThreadInfo threadInfo : threadInfos) {
dump.append('"');
dump.append(threadInfo.getThreadName());
dump.append("\" ");
final Thread.State state = threadInfo.getThreadState();
dump.append("\n java.lang.Thread.State: ");
dump.append(state);
final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
for (final StackTraceElement stackTraceElement : stackTraceElements) {
dump.append("\n at ");
dump.append(stackTraceElement);
}
dump.append("\n\n");
}
return dump.toString();
}
use of java.lang.management.ThreadInfo in project pinpoint by naver.
the class AgentActiveThreadDumpListSerializerTest method serializeTest.
@Test
public void serializeTest() throws Exception {
ThreadInfo[] allThreadInfo = ThreadMXBeanUtils.dumpAllThread();
AgentActiveThreadDumpList activeThreadDumpList = createThreadDumpList(allThreadInfo);
String jsonValue = mapper.writeValueAsString(activeThreadDumpList);
List list = mapper.readValue(jsonValue, List.class);
Assert.assertTrue(CollectionUtils.isNotEmpty(list));
Map map = (Map) list.get(0);
Assert.assertTrue(map.containsKey("threadId"));
Assert.assertTrue(map.containsKey("threadName"));
Assert.assertTrue(map.containsKey("threadState"));
Assert.assertTrue(map.containsKey("startTime"));
Assert.assertTrue(map.containsKey("execTime"));
Assert.assertTrue(map.containsKey("localTraceId"));
Assert.assertTrue(map.containsKey("sampled"));
Assert.assertTrue(map.containsKey("transactionId"));
Assert.assertTrue(map.containsKey("entryPoint"));
Assert.assertTrue(map.containsKey("detailMessage"));
}
use of java.lang.management.ThreadInfo in project pinpoint by naver.
the class AgentActiveThreadDumpListSerializerTest method createThreadDumpList.
private AgentActiveThreadDumpList createThreadDumpList(ThreadInfo[] allThreadInfo) {
List<TActiveThreadDump> activeThreadDumpList = new ArrayList<>();
for (ThreadInfo threadInfo : allThreadInfo) {
TActiveThreadDump tActiveThreadDump = new TActiveThreadDump();
tActiveThreadDump.setStartTime(System.currentTimeMillis() - 1000);
tActiveThreadDump.setThreadDump(ThreadDumpUtils.createTThreadDump(threadInfo));
activeThreadDumpList.add(tActiveThreadDump);
}
AgentActiveThreadDumpFactory factory = new AgentActiveThreadDumpFactory();
return factory.create1(activeThreadDumpList);
}
use of java.lang.management.ThreadInfo in project hadoop by apache.
the class TestRpcBase method countThreads.
/**
* Count the number of threads that have a stack frame containing
* the given string
*/
protected static int countThreads(String search) {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
int count = 0;
ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
for (ThreadInfo info : infos) {
if (info == null)
continue;
for (StackTraceElement elem : info.getStackTrace()) {
if (elem.getClassName().contains(search)) {
count++;
break;
}
}
}
return count;
}
use of java.lang.management.ThreadInfo in project hadoop by apache.
the class TestShell method countTimerThreads.
private static int countTimerThreads() {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
int count = 0;
ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
for (ThreadInfo info : infos) {
if (info == null)
continue;
for (StackTraceElement elem : info.getStackTrace()) {
if (elem.getClassName().contains("Timer")) {
count++;
break;
}
}
}
return count;
}
Aggregations