スレッドプールのコアパラメータを動的に調整する

プロジェクト

apollo 設定は、apollo 設定が変更されたかどうかを監視するために使用され、変更があった場合には、スレッド プールのパラメータ変更メソッドが呼び出されます。

キーコード

ThreadPoolTask​​Executor.setCorePoolSize(cpuCoreSize);
ThreadPoolTask​​Executor.setMaxPoolSize(maxCoreSize);

public static final String CPU_CORE_SIZE = "cpuCoreSize";
public static final String MAX_CORE_SIZE = "maxCoreSize";

@ApolloConfigChangeListener("")
public void doThreadChangeHandler(ConfigChangeEvent changeEvent) throws Exception {
    if(changeEvent.isChanged(CPU_CORE_SIZE) || changeEvent.isChanged(MAX_CORE_SIZE)) {
        ThreadPoolTaskExecutor asyncPool = ThreadPoolUtil.getAsyncPool();
        log.info("doThreadChangeHandler start : old cpuCoreSize : {},old maxPoolSize : {}", asyncPool.getCorePoolSize(), asyncPool.getMaxPoolSize());
        int cpuCoreSize = Integer.valueOf(changeEvent.getChange(CPU_CORE_SIZE).getNewValue());
        int maxCoreSize = Integer.valueOf(changeEvent.getChange(MAX_CORE_SIZE).getNewValue());
        ThreadPoolUtil.getAsyncPool().setCorePoolSize(cpuCoreSize);
        ThreadPoolUtil.getAsyncPool().setMaxPoolSize(maxCoreSize);
        log.info("doThreadChangeHandler start : new cpuCoreSize : {},new maxPoolSize : {}", asyncPool.getCorePoolSize(), asyncPool.getMaxPoolSize());
    }

}

おすすめ

転載: blog.csdn.net/qq_44961149/article/details/132448818