需求
- 实现自定义线程池
- 实现线程池参数动态刷新
自定义动态线程池模板
自定义动态线程池代码
@Data
@Slf4j
@Configuration
@RefreshScope
@ConfigurationProperties("custom.threadpool")
public class DemoThreadPool implements InitializingBean {
/**
* thread name format
*/
public static final String DEMO_THREAD_NAME = "DEMO-THREAD-%d";
/**
* core pool size, default: 8
* 1、CPU-intensive: CPU-cores + 1
* 2、IO intensive:CPU-cores/(1-blocking-factor), blocking factor: 0.8~0.9
*/
@Value("${corePoolSize:8}")
private Integer corePoolSize;
/**
* max pool size, default: 100
*/
@Value("${maxPoolSize:100}")
private Integer maximumPoolSize;
/**
* idle thread keep alive time (unit: s), default: 60
*/
@Value("${keepAliveTime:60}")
private Long keepAliveTime;
/**
* queue capacity size, default: 16
*/
@Value("${capacitySize:16}")
private Integer capacitySize;
/**
* dynamic refresh switch, default: false
*/
@Value("${dynamicRefreshSwitch:false}")
private Boolean dynamicRefreshSwitch;
/**
* listened service's nacos dataId
*/
@Value("${dataId:demo-service}")
private String dataId;
/**
* thread pool executor
*/
public