Search in sources :

Example 71 with ThreadMXBean

use of java.lang.management.ThreadMXBean 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 72 with ThreadMXBean

use of java.lang.management.ThreadMXBean 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)

Example 73 with ThreadMXBean

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

the class ReconnectTest method reconnectStressTest.

// it takes very long time. 
// @Test
@Ignore
public void reconnectStressTest() throws IOException, InterruptedException {
    int count = 3;
    ThreadMXBean tbean = ManagementFactory.getThreadMXBean();
    int threadCount = tbean.getThreadCount();
    for (int i = 0; i < count; i++) {
        logger.debug((i + 1) + "th's start.");
        PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE);
        PinpointClient client = clientFactory.connect("localhost", bindPort);
        PinpointRPCTestUtils.close(serverAcceptor);
        logger.debug("server.close");
        assertClientDisconnected(client);
        serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_ECHO_INSTANCE);
        logger.debug("bind server");
        assertClientConnected(client);
        logger.debug("request server");
        byte[] randomByte = TestByteUtils.createRandomByte(10);
        byte[] response = PinpointRPCTestUtils.request(client, randomByte);
        Assert.assertArrayEquals(randomByte, response);
        PinpointRPCTestUtils.close(client);
        PinpointRPCTestUtils.close(serverAcceptor);
    }
    Thread.sleep(10000);
    Assert.assertEquals(threadCount, tbean.getThreadCount());
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) PinpointServerAcceptor(com.navercorp.pinpoint.rpc.server.PinpointServerAcceptor)

Example 74 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project gerrit by GerritCodeReview.

the class StartStopDaemonIT method sandboxedDaemonDoesNotLeakThreads.

@Test
public void sandboxedDaemonDoesNotLeakThreads() throws Exception {
    ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
    int startThreads = thbean.getThreadCount();
    beforeTest(suiteDescription);
    afterTest();
    assertThat(Thread.activeCount()).isLessThan(startThreads);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 75 with ThreadMXBean

use of java.lang.management.ThreadMXBean 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

ThreadMXBean (java.lang.management.ThreadMXBean)105 ThreadInfo (java.lang.management.ThreadInfo)56 HashMap (java.util.HashMap)9 RuntimeMXBean (java.lang.management.RuntimeMXBean)8 MemoryMXBean (java.lang.management.MemoryMXBean)7 IOException (java.io.IOException)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)4 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)4 MemoryUsage (java.lang.management.MemoryUsage)4 HealthCheckResultEntry (fish.payara.notification.healthcheck.HealthCheckResultEntry)3 HealthCheckResult (fish.payara.nucleus.healthcheck.HealthCheckResult)3 LockInfo (java.lang.management.LockInfo)3 ManagementFactory (java.lang.management.ManagementFactory)3 MonitorInfo (java.lang.management.MonitorInfo)3