1、复制到项目lib下

2、File->Project Structure... ->Modeles ->Dependencies


找到目录下的jar包引用进去
3、配置pom.xml
<!--动态线程池配置 begin-->
<dependency>
<groupId>com.spz</groupId>
<artifactId>dtp-spring-boot-starter</artifactId>
<version>0.0.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/dtp-spring-boot-starter.jar</systemPath>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.7</version>
</dependency>
<!--动态线程池配置 end-->
这个支持nacos动态更改内置nacos的监听事件所以引用了nacos 也可也在yaml里使用
若使用nacos请配置dtp.yaml文件
如下
#nacos配置
nacos:
config:
server-addr: 127.0.0.1:8848
data-id: dtp.yaml
type: yaml
auto-refresh: true
bootstrap:
enable: true
dtp.yaml的配置如下
#动态配置
dtp:
executors:
- name: t1
core-pool-size: 10
maximum-pool-Size: 100
- name: t2
core-pool-size: 20
maximum-pool-Size: 110
name为使用线程池的名称 使用案例如下
@GetMapping("/test1")
public Integer test1() {
DtpExecutor t1 = DtpUtil.get("t1");
t1.execute(() -> doTask());
return t1.getCorePoolSize();
}
@GetMapping("/test2")
public Integer test2() {
DtpExecutor t2 = DtpUtil.get("t2");
t2.execute(() -> doTask());
return t2.getCorePoolSize();
}
所用jar包
https://pan.xunlei.com/s/VNFwDN8GhAarxCV8wzxQv7EeA1?pwd=38cc#
提取码:38cc