Search in sources :

Example 1 with RpcThreadPoolMonitor

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());
        }
    }
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) UserThreadPool(com.alipay.sofa.rpc.server.UserThreadPool) HashSet(java.util.HashSet)

Example 2 with RpcThreadPoolMonitor

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);
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) Field(java.lang.reflect.Field) List(java.util.List) Method(java.lang.reflect.Method) UserThreadPool(com.alipay.sofa.rpc.server.UserThreadPool) ActivelyDestroyTest(com.alipay.sofa.rpc.boot.test.ActivelyDestroyTest) Test(org.junit.Test)

Example 3 with RpcThreadPoolMonitor

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());
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Example 4 with RpcThreadPoolMonitor

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);
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Example 5 with RpcThreadPoolMonitor

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());
        }
    }
}
Also used : RpcThreadPoolMonitor(com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor) UserThreadPool(com.alipay.sofa.rpc.server.UserThreadPool) HashSet(java.util.HashSet)

Aggregations

RpcThreadPoolMonitor (com.alipay.sofa.rpc.boot.common.RpcThreadPoolMonitor)8 Test (org.junit.Test)6 UserThreadPool (com.alipay.sofa.rpc.server.UserThreadPool)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 ActivelyDestroyTest (com.alipay.sofa.rpc.boot.test.ActivelyDestroyTest)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 HashSet (java.util.HashSet)2 List (java.util.List)2