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;
}
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;
}
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());
}
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);
}
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);
}
Aggregations