Search in sources :

Example 91 with ThreadInfo

use of java.lang.management.ThreadInfo in project druid by alibaba.

the class Case4 method p0.

private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {
    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(threadCount);
    final CountDownLatch dumpLatch = new CountDownLatch(1);
    Thread[] threads = new Thread[threadCount];
    final TableOperator operator = new TableOperator();
    operator.setDataSource(dataSource);
    operator.createTable();
    for (int i = 0; i < threadCount; ++i) {
        Thread thread = new Thread() {

            public void run() {
                try {
                    startLatch.await();
                    for (int i = 0; i < LOOP_COUNT; ++i) {
                        operator.insert();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                endLatch.countDown();
                try {
                    dumpLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        threads[i] = thread;
        thread.start();
    }
    long startMillis = System.currentTimeMillis();
    long startYGC = TestUtil.getYoungGC();
    long startFullGC = TestUtil.getFullGC();
    startLatch.countDown();
    endLatch.await();
    long[] threadIdArray = new long[threads.length];
    for (int i = 0; i < threads.length; ++i) {
        threadIdArray[i] = threads[i].getId();
    }
    ThreadInfo[] threadInfoArray = ManagementFactory.getThreadMXBean().getThreadInfo(threadIdArray);
    dumpLatch.countDown();
    operator.dropTable();
    long blockedCount = 0;
    long waitedCount = 0;
    for (int i = 0; i < threadInfoArray.length; ++i) {
        ThreadInfo threadInfo = threadInfoArray[i];
        blockedCount += threadInfo.getBlockedCount();
        waitedCount += threadInfo.getWaitedCount();
    }
    long millis = System.currentTimeMillis() - startMillis;
    long ygc = TestUtil.getYoungGC() - startYGC;
    long fullGC = TestUtil.getFullGC() - startFullGC;
    System.out.println("thread " + threadCount + " " + name + " millis : " + NumberFormat.getInstance().format(millis) + "; YGC " + ygc + " FGC " + fullGC + " blocked " + //
    NumberFormat.getInstance().format(blockedCount) + " waited " + NumberFormat.getInstance().format(waitedCount));
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) TableOperator(com.alibaba.druid.benckmark.pool.model.TableOperator) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 92 with ThreadInfo

use of java.lang.management.ThreadInfo in project intellij-plugins by JetBrains.

the class HealthUtils method logThreads.

/**
   * Log data about threads to the provided instrumentation builder
   * 
   * @param instrumentation builder to log data to
   */
public static void logThreads(InstrumentationBuilder instrumentation) {
    java.lang.management.ThreadMXBean th = ManagementFactory.getThreadMXBean();
    ThreadInfo[] thInfos = th.getThreadInfo(th.getAllThreadIds(), Integer.MAX_VALUE);
    instrumentation.metric("threads-count", thInfos.length);
    for (ThreadInfo thInfo : thInfos) {
        if (thInfo == null) {
            instrumentation.metric("Thread-Name", "<unknown>");
            continue;
        }
        instrumentation.metric("Thread-Name", thInfo.getThreadName());
        instrumentation.metric("Thread-ID", thInfo.getThreadId());
        instrumentation.metric("Thread-State", thInfo.getThreadState().toString());
        instrumentation.metric("Blocked-Count", thInfo.getBlockedCount());
        instrumentation.metric("Blocked-Time", thInfo.getBlockedTime());
        instrumentation.metric("Waited-Count", thInfo.getWaitedCount());
        instrumentation.metric("Waited-Time", thInfo.getWaitedTime());
        instrumentation.data("Thread-ST", Base64.encodeBytes(stackTraceToString(thInfo.getStackTrace()).getBytes()));
    }
}
Also used : ThreadInfo(java.lang.management.ThreadInfo)

Example 93 with ThreadInfo

use of java.lang.management.ThreadInfo in project OpenAM by OpenRock.

the class RecordReport method getThreadDump.

public String getThreadDump() {
    StringBuilder report = new StringBuilder();
    report.append("DATE : ").append(dateFormat.format(new Date())).append("\n");
    final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100);
    for (ThreadInfo threadInfo : threadInfos) {
        report.append(threadInfo);
    }
    return report.toString();
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) Date(java.util.Date)

Example 94 with ThreadInfo

use of java.lang.management.ThreadInfo in project opennms by OpenNMS.

the class ThreadReportPlugin method getEntries.

@Override
public Map<String, Resource> getEntries() {
    final Map<String, Resource> map = new TreeMap<String, Resource>();
    final StringBuilder sb = new StringBuilder();
    try {
        final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
        for (final ThreadInfo info : threads) {
            sb.append(info.toString());
        }
        map.put("ThreadDump.txt", getResource(sb.toString()));
    } catch (final Exception e) {
        LOG.debug("Unable to get thread dump.", e);
    }
    return map;
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) Resource(org.springframework.core.io.Resource) TreeMap(java.util.TreeMap)

Example 95 with ThreadInfo

use of java.lang.management.ThreadInfo in project geode by apache.

the class DeadlockDetector method getThreadReference.

/**
   * Get an object suitable for querying the findDependencies method for a given thread.
   */
public static ThreadReference getThreadReference(String locality, Thread thread) {
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    ThreadInfo info = bean.getThreadInfo(thread.getId(), Integer.MAX_VALUE);
    return new LocalThread(locality, info);
}
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