Search in sources :

Example 81 with ThreadInfo

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();
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Example 82 with ThreadInfo

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"));
}
Also used : AgentActiveThreadDumpList(com.navercorp.pinpoint.web.vo.AgentActiveThreadDumpList) ThreadInfo(java.lang.management.ThreadInfo) ArrayList(java.util.ArrayList) List(java.util.List) AgentActiveThreadDumpList(com.navercorp.pinpoint.web.vo.AgentActiveThreadDumpList) Map(java.util.Map) Test(org.junit.Test)

Example 83 with ThreadInfo

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);
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) AgentActiveThreadDumpFactory(com.navercorp.pinpoint.web.vo.AgentActiveThreadDumpFactory) ArrayList(java.util.ArrayList) TActiveThreadDump(com.navercorp.pinpoint.thrift.dto.command.TActiveThreadDump)

Example 84 with ThreadInfo

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;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Example 85 with ThreadInfo

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;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Aggregations

ThreadInfo (java.lang.management.ThreadInfo)124 ThreadMXBean (java.lang.management.ThreadMXBean)56 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)7 Map (java.util.Map)7 LockInfo (java.lang.management.LockInfo)6 MonitorInfo (java.lang.management.MonitorInfo)6 Test (org.junit.Test)5 Date (java.util.Date)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 FileOutputStream (java.io.FileOutputStream)3 PrintStream (java.io.PrintStream)3 PrintWriter (java.io.PrintWriter)3 Method (java.lang.reflect.Method)3 LinkedHashSet (java.util.LinkedHashSet)3 TreeMap (java.util.TreeMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 HealthCheckResultEntry (fish.payara.notification.healthcheck.HealthCheckResultEntry)2