fix:default fill config (#1041)

* fix:default fill config

* fix:default fill config
pull/1064/head
WuLang 3 years ago committed by GitHub
parent 0f5cb2c7fb
commit d05efb466b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -107,6 +107,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
.findFirst() .findFirst()
.orElseThrow(() -> new RuntimeException("The thread pool id does not exist in the configuration.")); .orElseThrow(() -> new RuntimeException("The thread pool id does not exist in the configuration."));
try { try {
executorProperties = buildActualExecutorProperties(executorProperties);
threadPoolParamReplace(executor, executorProperties); threadPoolParamReplace(executor, executorProperties);
} catch (Exception ex) { } catch (Exception ex) {
log.error("Failed to initialize thread pool configuration.", ex); log.error("Failed to initialize thread pool configuration.", ex);
@ -121,7 +122,7 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
threadPoolId, threadPoolId,
executorProperties == null executorProperties == null
? buildDefaultExecutorProperties(threadPoolId, executor) ? buildDefaultExecutorProperties(threadPoolId, executor)
: buildActualExecutorProperties(executorProperties)); : executorProperties);
return executor; return executor;
} }
@ -188,27 +189,26 @@ public final class DynamicThreadPoolPostProcessor implements BeanPostProcessor {
* @return executor properties * @return executor properties
*/ */
private ExecutorProperties buildExecutorProperties(ExecutorProperties executorProperties) { private ExecutorProperties buildExecutorProperties(ExecutorProperties executorProperties) {
ExecutorProperties newExecutorProperties = ExecutorProperties.builder() return ExecutorProperties.builder()
.corePoolSize(Optional.ofNullable(executorProperties.getCorePoolSize()) .corePoolSize(Optional.ofNullable(executorProperties.getCorePoolSize())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getCorePoolSize()).get())) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getCorePoolSize).get()))
.maximumPoolSize(Optional.ofNullable(executorProperties.getMaximumPoolSize()) .maximumPoolSize(Optional.ofNullable(executorProperties.getMaximumPoolSize())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getMaximumPoolSize()).get())) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getMaximumPoolSize).get()))
.allowCoreThreadTimeOut(Optional.ofNullable(executorProperties.getAllowCoreThreadTimeOut()) .allowCoreThreadTimeOut(Optional.ofNullable(executorProperties.getAllowCoreThreadTimeOut())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getAllowCoreThreadTimeOut()).get())) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getAllowCoreThreadTimeOut).get()))
.keepAliveTime(Optional.ofNullable(executorProperties.getKeepAliveTime()) .keepAliveTime(Optional.ofNullable(executorProperties.getKeepAliveTime())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getKeepAliveTime()).get())) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getKeepAliveTime).get()))
.blockingQueue(Optional.ofNullable(executorProperties.getBlockingQueue()) .blockingQueue(Optional.ofNullable(executorProperties.getBlockingQueue())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getBlockingQueue()).get())) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getBlockingQueue).get()))
.executeTimeOut(Optional.ofNullable(executorProperties.getExecuteTimeOut()) .executeTimeOut(Optional.ofNullable(executorProperties.getExecuteTimeOut())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getExecuteTimeOut()).orElse(0L))) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getExecuteTimeOut).orElse(0L)))
.queueCapacity(Optional.ofNullable(executorProperties.getQueueCapacity()) .queueCapacity(Optional.ofNullable(executorProperties.getQueueCapacity())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getQueueCapacity()).get())) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getQueueCapacity).get()))
.rejectedHandler(Optional.ofNullable(executorProperties.getRejectedHandler()) .rejectedHandler(Optional.ofNullable(executorProperties.getRejectedHandler())
.orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(each -> each.getRejectedHandler()).get())) .orElseGet(() -> Optional.ofNullable(configProperties.getDefaultExecutor()).map(ExecutorProperties::getRejectedHandler).get()))
.threadNamePrefix(StringUtil.isBlank(executorProperties.getThreadNamePrefix()) ? executorProperties.getThreadPoolId() : executorProperties.getThreadNamePrefix()) .threadNamePrefix(StringUtil.isBlank(executorProperties.getThreadNamePrefix()) ? executorProperties.getThreadPoolId() : executorProperties.getThreadNamePrefix())
.threadPoolId(executorProperties.getThreadPoolId()) .threadPoolId(executorProperties.getThreadPoolId())
.build(); .build();
return newExecutorProperties;
} }
/** /**

Loading…
Cancel
Save