optimize: 线程池构造器创建自定义线程池, 线程池标识默认线程工厂前缀, 简化创建流程.

pull/161/head v0.4.0
chen.ma 3 years ago
parent bd745ab6c2
commit 3f8df895e0

@ -5,6 +5,7 @@ import com.github.dynamic.threadpool.common.toolkit.Assert;
import com.github.dynamic.threadpool.starter.alarm.ThreadPoolAlarm; import com.github.dynamic.threadpool.starter.alarm.ThreadPoolAlarm;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Optional;
import java.util.concurrent.*; import java.util.concurrent.*;
/** /**
@ -267,7 +268,8 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
.setTimeUnit(builder.timeUnit); .setTimeUnit(builder.timeUnit);
if (builder.isCustomPool) { if (builder.isCustomPool) {
initParam.setThreadPoolId(builder.threadPoolId); String threadPoolId = Optional.ofNullable(builder.threadPoolId).orElse(builder.threadNamePrefix);
initParam.setThreadPoolId(threadPoolId);
ThreadPoolAlarm threadPoolAlarm = new ThreadPoolAlarm(builder.isAlarm, builder.capacityAlarm, builder.livenessAlarm); ThreadPoolAlarm threadPoolAlarm = new ThreadPoolAlarm(builder.isAlarm, builder.capacityAlarm, builder.livenessAlarm);
initParam.setThreadPoolAlarm(threadPoolAlarm); initParam.setThreadPoolAlarm(threadPoolAlarm);
} }

@ -42,7 +42,7 @@ public class ThreadPoolConfig {
@Bean @Bean
@DynamicThreadPool @DynamicThreadPool
public ThreadPoolExecutor customThreadPoolExecutor() { public ThreadPoolExecutor customThreadPoolExecutor() {
return ThreadPoolBuilder.builder().threadFactory(MESSAGE_PRODUCE).threadPoolId(MESSAGE_PRODUCE).isCustomPool(true).build(); return ThreadPoolBuilder.builder().threadFactory(MESSAGE_PRODUCE).isCustomPool(true).build();
} }
} }

Loading…
Cancel
Save