配置类
1 2 3 4 5 6 7 8 9 10
| @ConfigurationProperties(prefix = "gulimall.thread") @Component @Data public class ThreadPoolProperties {
private Integer coreSize = 50; private Integer maxSize = 200; private Integer keepAlive = 10;
}
|
依赖
导入后重启项目可在properties文件中提示,也可不导入
1 2 3 4
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> </dependency>
|
使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| @Configuration public class MyThreadConfig {
public ThreadPoolExecutor threadPoolExecutor(ThreadPoolProperties pool){ return new ThreadPoolExecutor( pool.getCoreSize(), pool.getMaxSize(), pool.getKeepAlive(), TimeUnit.SECONDS, new LinkedBlockingDeque<>(100000), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy()); }
}
|