@ -15,7 +15,6 @@ import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper ;
import cn.hippo4j.starter.wrapper.DynamicThreadPoolWrapper ;
import lombok.AllArgsConstructor ;
import lombok.AllArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import lombok.var ;
import org.springframework.beans.BeansException ;
import org.springframework.beans.BeansException ;
import org.springframework.beans.factory.config.BeanPostProcessor ;
import org.springframework.beans.factory.config.BeanPostProcessor ;
import org.springframework.core.task.TaskDecorator ;
import org.springframework.core.task.TaskDecorator ;
@ -54,24 +53,24 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
. workQueue ( QueueTypeEnum . ARRAY_BLOCKING_QUEUE )
. workQueue ( QueueTypeEnum . ARRAY_BLOCKING_QUEUE )
. capacity ( 1024 )
. capacity ( 1024 )
. allowCoreThreadTimeOut ( true )
. allowCoreThreadTimeOut ( true )
. threadFactory ( " dynamic-threadPool-change- config")
. threadFactory ( " client.dynamic.threadPool.change. config")
. rejected ( new ThreadPoolExecutor . AbortPolicy ( ) )
. rejected ( new ThreadPoolExecutor . AbortPolicy ( ) )
. build ( ) ;
. build ( ) ;
@Override
@Override
public Object postProcessAfterInitialization ( Object bean , String beanName ) throws BeansException {
public Object postProcessAfterInitialization ( Object bean , String beanName ) throws BeansException {
if ( bean instanceof DynamicThreadPoolExecutor ) {
if ( bean instanceof DynamicThreadPoolExecutor ) {
var dynamicThreadPool = ApplicationContextHolder . findAnnotationOnBean ( beanName , DynamicThreadPool . class ) ;
DynamicThreadPool dynamicThreadPool = ApplicationContextHolder . findAnnotationOnBean ( beanName , DynamicThreadPool . class ) ;
if ( Objects . isNull ( dynamicThreadPool ) ) {
if ( Objects . isNull ( dynamicThreadPool ) ) {
return bean ;
return bean ;
}
}
va r dynamicExecutor = ( DynamicThreadPoolExecutor ) bean ;
DynamicThreadPoolExecuto r dynamicExecutor = ( DynamicThreadPoolExecutor ) bean ;
va r wrap = new DynamicThreadPoolWrapper ( dynamicExecutor . getThreadPoolId ( ) , dynamicExecutor ) ;
DynamicThreadPoolWrappe r wrap = new DynamicThreadPoolWrapper ( dynamicExecutor . getThreadPoolId ( ) , dynamicExecutor ) ;
va r remoteExecutor = fillPoolAndRegister ( wrap ) ;
ThreadPoolExecuto r remoteExecutor = fillPoolAndRegister ( wrap ) ;
subscribeConfig ( wrap ) ;
subscribeConfig ( wrap ) ;
return remoteExecutor ;
return remoteExecutor ;
} else if ( bean instanceof DynamicThreadPoolWrapper ) {
} else if ( bean instanceof DynamicThreadPoolWrapper ) {
va r wrap = ( DynamicThreadPoolWrapper ) bean ;
DynamicThreadPoolWrappe r wrap = ( DynamicThreadPoolWrapper ) bean ;
registerAndSubscribe ( wrap ) ;
registerAndSubscribe ( wrap ) ;
}
}
@ -136,7 +135,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
poolExecutor = dynamicThreadPoolWrap . getExecutor ( ) ! = null ? dynamicThreadPoolWrap . getExecutor ( ) : CommonDynamicThreadPool . getInstance ( tpId ) ;
poolExecutor = dynamicThreadPoolWrap . getExecutor ( ) ! = null ? dynamicThreadPoolWrap . getExecutor ( ) : CommonDynamicThreadPool . getInstance ( tpId ) ;
dynamicThreadPoolWrap . setExecutor ( poolExecutor ) ;
dynamicThreadPoolWrap . setExecutor ( poolExecutor ) ;
log . error ( " [Init pool] Failed to initialize thread pool configuration. error message :: {}", ex . getMessage ( ) ) ;
log . error ( " Failed to initialize thread pool configuration. error message :: {}", ex . getMessage ( ) ) ;
} finally {
} finally {
if ( Objects . isNull ( dynamicThreadPoolWrap . getExecutor ( ) ) ) {
if ( Objects . isNull ( dynamicThreadPoolWrap . getExecutor ( ) ) ) {
dynamicThreadPoolWrap . setExecutor ( CommonDynamicThreadPool . getInstance ( tpId ) ) ;
dynamicThreadPoolWrap . setExecutor ( CommonDynamicThreadPool . getInstance ( tpId ) ) ;