Skip to content

Commit

Permalink
optimize: 线程池构造器创建自定义线程池, 线程池标识默认线程工厂前缀, 简化创建流程.
Browse files Browse the repository at this point in the history
  • Loading branch information
magestacks committed Oct 27, 2021
1 parent bd745ab commit 3f8df89
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.dynamic.threadpool.starter.alarm.ThreadPoolAlarm;

import java.math.BigDecimal;
import java.util.Optional;
import java.util.concurrent.*;

/**
Expand Down Expand Up @@ -267,7 +268,8 @@ private static AbstractBuildThreadPoolTemplate.ThreadPoolInitParam buildInitPara
.setTimeUnit(builder.timeUnit);

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);
initParam.setThreadPoolAlarm(threadPoolAlarm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public DynamicThreadPoolWrap messageCenterConsumeThreadPool() {
@Bean
@DynamicThreadPool
public ThreadPoolExecutor customThreadPoolExecutor() {
return ThreadPoolBuilder.builder().threadFactory(MESSAGE_PRODUCE).threadPoolId(MESSAGE_PRODUCE).isCustomPool(true).build();
return ThreadPoolBuilder.builder().threadFactory(MESSAGE_PRODUCE).isCustomPool(true).build();
}

}

0 comments on commit 3f8df89

Please sign in to comment.