Search in sources :

Example 86 with ThreadInfo

use of java.lang.management.ThreadInfo in project pinpoint by naver.

the class AgentEventMessageSerDesTest method createTCommandThreadDumpResponse.

private TCommandThreadDumpResponse createTCommandThreadDumpResponse() {
    final TCommandThreadDumpResponse threadDumpResponse = new TCommandThreadDumpResponse();
    ThreadInfo[] threadInfos = ThreadMXBeanUtils.dumpAllThread();
    for (ThreadInfo threadInfo : threadInfos) {
        final TThreadDump threadDump = createTThreadDump(threadInfo);
        threadDumpResponse.addToThreadDumps(threadDump);
    }
    return threadDumpResponse;
}
Also used : TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) ThreadInfo(java.lang.management.ThreadInfo) TThreadDump(com.navercorp.pinpoint.thrift.dto.command.TThreadDump)

Example 87 with ThreadInfo

use of java.lang.management.ThreadInfo in project pinpoint by naver.

the class ThreadMXBeanUtils method findThread.

public static List<ThreadInfo> findThread(String threadName) {
    Asserts.notNull(threadName, "threadName may not be null.");
    ThreadInfo[] threadInfos = dumpAllThread();
    if (threadInfos == null) {
        return Collections.emptyList();
    }
    ArrayList<ThreadInfo> threadInfoList = new ArrayList<ThreadInfo>(1);
    for (ThreadInfo threadInfo : threadInfos) {
        if (threadName.equals(threadInfo.getThreadName())) {
            threadInfoList.add(threadInfo);
        }
    }
    return threadInfoList;
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) ArrayList(java.util.ArrayList)

Example 88 with ThreadInfo

use of java.lang.management.ThreadInfo in project pinpoint by naver.

the class ThreadDumpService method requestCommandService.

@Override
public TBase<?, ?> requestCommandService(TBase tbase) {
    logger.info("{} execute {}.", this, tbase);
    TCommandThreadDump param = (TCommandThreadDump) tbase;
    TThreadDumpType type = param.getType();
    List<ThreadInfo> threadInfoList = null;
    if (TThreadDumpType.TARGET == type) {
        threadInfoList = getThreadInfo(param.getName());
    } else if (TThreadDumpType.PENDING == type) {
        threadInfoList = getThreadInfo(param.getPendingTimeMillis());
    } else {
        threadInfoList = Arrays.asList(getAllThreadInfo());
    }
    TCommandThreadDumpResponse response = new TCommandThreadDumpResponse();
    for (ThreadInfo info : threadInfoList) {
        TThreadDump dump = new TThreadDump();
        dump.setThreadName(info.getThreadName());
        dump.setThreadId(info.getThreadId());
        dump.setBlockedTime(info.getBlockedTime());
        dump.setBlockedCount(info.getBlockedCount());
        dump.setWaitedTime(info.getWaitedTime());
        dump.setWaitedCount(info.getWaitedCount());
        dump.setLockName(info.getLockName());
        dump.setLockOwnerId(info.getLockOwnerId());
        dump.setLockOwnerName(info.getLockOwnerName());
        dump.setInNative(info.isInNative());
        dump.setSuspended(info.isSuspended());
        dump.setThreadState(getThreadState(info));
        StackTraceElement[] stackTraceElements = info.getStackTrace();
        for (StackTraceElement each : stackTraceElements) {
            dump.addToStackTrace(each.toString());
        }
        MonitorInfo[] monitorInfos = info.getLockedMonitors();
        for (MonitorInfo each : monitorInfos) {
            TMonitorInfo tMonitorInfo = new TMonitorInfo();
            tMonitorInfo.setStackDepth(each.getLockedStackDepth());
            tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString());
            dump.addToLockedMonitors(tMonitorInfo);
        }
        LockInfo[] lockInfos = info.getLockedSynchronizers();
        for (LockInfo lockInfo : lockInfos) {
            dump.addToLockedSynchronizers(lockInfo.toString());
        }
        response.addToThreadDumps(dump);
    }
    return response;
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) ThreadInfo(java.lang.management.ThreadInfo) LockInfo(java.lang.management.LockInfo)

Example 89 with ThreadInfo

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

the class Case1 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];
    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) {
                        Connection conn = dataSource.getConnection();
                        conn.close();
                    }
                } 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();
    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) + " physicalConn " + physicalConnStat.get());
}
Also used : ThreadInfo(java.lang.management.ThreadInfo) Connection(java.sql.Connection) CountDownLatch(java.util.concurrent.CountDownLatch) SQLException(java.sql.SQLException)

Example 90 with ThreadInfo

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

the class Case2 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 AtomicLong blockedStat = new AtomicLong();
    final AtomicLong waitedStat = new AtomicLong();
    for (int i = 0; i < threadCount; ++i) {
        Thread thread = new Thread() {

            public void run() {
                try {
                    startLatch.await();
                    long threadId = Thread.currentThread().getId();
                    long startBlockedCount, startWaitedCount;
                    {
                        ThreadInfo threadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(threadId);
                        startBlockedCount = threadInfo.getBlockedCount();
                        startWaitedCount = threadInfo.getWaitedCount();
                    }
                    for (int i = 0; i < LOOP_COUNT; ++i) {
                        Connection conn = dataSource.getConnection();
                        conn.close();
                    }
                    ThreadInfo threadInfo = ManagementFactory.getThreadMXBean().getThreadInfo(threadId);
                    long blockedCount = threadInfo.getBlockedCount() - startBlockedCount;
                    long waitedCount = threadInfo.getWaitedCount() - startWaitedCount;
                    blockedStat.addAndGet(blockedCount);
                    waitedStat.addAndGet(waitedCount);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                endLatch.countDown();
            }
        };
        thread.start();
    }
    long startMillis = System.currentTimeMillis();
    long startYGC = TestUtil.getYoungGC();
    long startFullGC = TestUtil.getFullGC();
    startLatch.countDown();
    endLatch.await();
    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 + " blockedCount " + blockedStat.get() + " waitedCount " + waitedStat.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ThreadInfo(java.lang.management.ThreadInfo) Connection(java.sql.Connection) CountDownLatch(java.util.concurrent.CountDownLatch)

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