From a9f6bb983549e69db03d4016e350f10cd11fe7ab Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Tue, 9 Aug 2022 12:24:29 +0800 Subject: [PATCH] hippo4j core adapts to Ali ttl --- .../support/DynamicThreadPoolPostProcessor.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java index 5661db92..5a44a5ae 100644 --- a/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java +++ b/hippo4j-spring-boot/hippo4j-core-spring-boot-starter/src/main/java/cn/hippo4j/core/springboot/starter/support/DynamicThreadPoolPostProcessor.java @@ -25,6 +25,7 @@ import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.manage.GlobalNotifyAlarmManage; import cn.hippo4j.core.executor.manage.GlobalThreadPoolManage; import cn.hippo4j.core.executor.support.*; +import cn.hippo4j.core.executor.support.adpter.DynamicThreadPoolAdapterChoose; import cn.hippo4j.core.springboot.starter.config.BootstrapCoreProperties; import cn.hippo4j.core.springboot.starter.config.ExecutorProperties; import cn.hippo4j.core.toolkit.inet.DynamicThreadPoolAnnotationUtil; @@ -57,7 +58,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof DynamicThreadPoolExecutor) { + if (bean instanceof DynamicThreadPoolExecutor || DynamicThreadPoolAdapterChoose.match(bean)) { DynamicThreadPool dynamicThreadPool; try { dynamicThreadPool = ApplicationContextHolder.findAnnotationOnBean(beanName, DynamicThreadPool.class); @@ -72,10 +73,14 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor { log.error("Failed to create dynamic thread pool in annotation mode.", ex); return bean; } - DynamicThreadPoolExecutor dynamicExecutor = (DynamicThreadPoolExecutor) bean; - DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicExecutor.getThreadPoolId(), dynamicExecutor); - ThreadPoolExecutor remoteExecutor = fillPoolAndRegister(wrap); - return remoteExecutor; + DynamicThreadPoolExecutor dynamicThreadPoolExecutor; + if ((dynamicThreadPoolExecutor = DynamicThreadPoolAdapterChoose.unwrap(bean)) == null) { + dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) bean; + } + DynamicThreadPoolWrapper wrap = new DynamicThreadPoolWrapper(dynamicThreadPoolExecutor.getThreadPoolId(), dynamicThreadPoolExecutor); + ThreadPoolExecutor remoteThreadPoolExecutor = fillPoolAndRegister(wrap); + DynamicThreadPoolAdapterChoose.replace(bean, remoteThreadPoolExecutor); + return remoteThreadPoolExecutor; } if (bean instanceof DynamicThreadPoolWrapper) { DynamicThreadPoolWrapper wrap = (DynamicThreadPoolWrapper) bean;