use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by sofastack.
the class ServerConfigContainer method startCustomThreadPoolMonitor.
private void startCustomThreadPoolMonitor() {
Set<UserThreadPool> userThreadPoolSet = UserThreadPoolManager.getUserThreadPoolSet();
if (!userThreadPoolSet.isEmpty()) {
Set<String> poolNames = new HashSet<>();
for (UserThreadPool pool : userThreadPoolSet) {
RpcThreadPoolMonitor customThreadPoolMonitor = new RpcThreadPoolMonitor(LoggerConstant.CUSTOM_THREAD_LOGGER_NAME);
customThreadPoolMonitorList.add(customThreadPoolMonitor);
if (poolNames.contains(pool.getThreadPoolName())) {
// use to distinguish some UserThreadPools set same poolName
customThreadPoolMonitor.setPoolName(pool.getThreadPoolName() + "-" + pool.hashCode());
} else {
customThreadPoolMonitor.setPoolName(pool.getThreadPoolName());
}
customThreadPoolMonitor.setThreadPoolExecutor(pool.getExecutor());
customThreadPoolMonitor.start();
poolNames.add(pool.getThreadPoolName());
}
}
}
use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by sofastack.
the class ServerConfigContainerTest method testStartCustomThreadPoolMonitor.
@Test
public void testStartCustomThreadPoolMonitor() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, NoSuchFieldException {
UserThreadPoolManager.registerUserThread("service1", new UserThreadPool());
UserThreadPoolManager.registerUserThread("service2", new UserThreadPool());
UserThreadPoolManager.registerUserThread("service3", new UserThreadPool("same-name"));
UserThreadPoolManager.registerUserThread("service4", new UserThreadPool("same-name"));
Method privateStartMethod = serverConfigContainer.getClass().getDeclaredMethod("startCustomThreadPoolMonitor");
privateStartMethod.setAccessible(true);
privateStartMethod.invoke(serverConfigContainer);
Field privateField = serverConfigContainer.getClass().getDeclaredField("customThreadPoolMonitorList");
privateField.setAccessible(true);
Object value = privateField.get(serverConfigContainer);
List<RpcThreadPoolMonitor> customThreadPoolMonitorList = (List<RpcThreadPoolMonitor>) value;
Assert.assertEquals(customThreadPoolMonitorList.size(), 4);
boolean hasHashCode = false;
for (RpcThreadPoolMonitor monitor : customThreadPoolMonitorList) {
if (monitor.getPoolName().contains("same-name-")) {
hasHashCode = true;
}
}
Assert.assertTrue(hasHashCode);
Method privateStopMethod = serverConfigContainer.getClass().getDeclaredMethod("stopCustomThreadPoolMonitor");
privateStopMethod.setAccessible(true);
privateStopMethod.invoke(serverConfigContainer);
Assert.assertEquals(customThreadPoolMonitorList.size(), 0);
}
use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by sofastack.
the class ThreadPoolMonitorTest method testTestStop.
@Test
public void testTestStop() throws InterruptedException {
ThreadPoolExecutor executorService = new ThreadPoolExecutor(10, 11, 1, TimeUnit.DAYS, new LinkedBlockingQueue<>(10));
RpcThreadPoolMonitor rpcThreadPoolMonitor = new RpcThreadPoolMonitor(executorService, LoggerConstant.TRIPLE_THREAD_LOGGER_NAME);
rpcThreadPoolMonitor.start();
Thread monitor = rpcThreadPoolMonitor.getMonitor();
Assert.assertFalse(Thread.State.TERMINATED == monitor.getState());
rpcThreadPoolMonitor.stop();
Thread.sleep(100);
System.out.println(monitor.getState());
Assert.assertTrue(Thread.State.TERMINATED == monitor.getState());
}
use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by sofastack.
the class ThreadPoolMonitorTest method test.
@Test
public void test() throws InterruptedException {
ThreadPoolExecutor executorService = new ThreadPoolExecutor(10, 11, 1, TimeUnit.DAYS, new LinkedBlockingQueue<>(10));
new RpcThreadPoolMonitor(executorService, LoggerConstant.TRIPLE_THREAD_LOGGER_NAME).start();
Thread.sleep(10000);
}
use of com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor in project sofa-boot by alipay.
the class ServerConfigContainer method startCustomThreadPoolMonitor.
private void startCustomThreadPoolMonitor() {
Set<UserThreadPool> userThreadPoolSet = UserThreadPoolManager.getUserThreadPoolSet();
if (!userThreadPoolSet.isEmpty()) {
Set<String> poolNames = new HashSet<>();
for (UserThreadPool pool : userThreadPoolSet) {
RpcThreadPoolMonitor customThreadPoolMonitor = new RpcThreadPoolMonitor(LoggerConstant.CUSTOM_THREAD_LOGGER_NAME);
customThreadPoolMonitorList.add(customThreadPoolMonitor);
if (poolNames.contains(pool.getThreadPoolName())) {
// use to distinguish some UserThreadPools set same poolName
customThreadPoolMonitor.setPoolName(pool.getThreadPoolName() + "-" + pool.hashCode());
} else {
customThreadPoolMonitor.setPoolName(pool.getThreadPoolName());
}
customThreadPoolMonitor.setThreadPoolExecutor(pool.getExecutor());
customThreadPoolMonitor.start();
poolNames.add(pool.getThreadPoolName());
}
}
}
Aggregations