Skip to content

Commit 484188d

Browse files
committed
feat: 提取 TTL、DynamicTp 到 plugin concorrent
1. 升级 DynamicTp 到 1.1.3 2. 分模块引入 hutool
1 parent 31c6bd5 commit 484188d

10 files changed

Lines changed: 135 additions & 30 deletions

File tree

business/sample/src/main/java/top/cadecode/uniboot/business/sample/controller/DynamicTpController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package top.cadecode.uniboot.business.sample.controller;
22

3-
import com.dtp.core.thread.DtpExecutor;
43
import io.swagger.annotations.Api;
54
import io.swagger.annotations.ApiOperation;
65
import lombok.RequiredArgsConstructor;
76
import lombok.extern.slf4j.Slf4j;
7+
import org.springframework.core.task.AsyncTaskExecutor;
88
import org.springframework.web.bind.annotation.PostMapping;
99
import org.springframework.web.bind.annotation.RequestMapping;
1010
import org.springframework.web.bind.annotation.RestController;
@@ -24,7 +24,7 @@
2424
@RequestMapping("demo/tp")
2525
public class DynamicTpController {
2626

27-
private final DtpExecutor asyncExecutor;
27+
private final AsyncTaskExecutor asyncExecutor;
2828

2929
@ApiOperation("测试 reject 通知")
3030
@PostMapping("test_reject")

common/core/pom.xml

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,19 @@
4343
<groupId>org.springframework.retry</groupId>
4444
<artifactId>spring-retry</artifactId>
4545
</dependency>
46-
<!--ttl-->
46+
<!--excel-->
4747
<dependency>
4848
<groupId>com.alibaba</groupId>
49-
<artifactId>transmittable-thread-local</artifactId>
49+
<artifactId>easyexcel</artifactId>
5050
</dependency>
51-
<!--dynamicTp-->
5251
<dependency>
53-
<groupId>cn.dynamictp</groupId>
54-
<artifactId>dynamic-tp-spring-boot-starter-common</artifactId>
52+
<groupId>cn.hutool</groupId>
53+
<artifactId>hutool-poi</artifactId>
5554
</dependency>
55+
<!--jwt-->
5656
<dependency>
57-
<groupId>cn.dynamictp</groupId>
58-
<artifactId>dynamic-tp-spring-boot-starter-extension-notify-email</artifactId>
59-
</dependency>
60-
<!--excel-->
61-
<dependency>
62-
<groupId>com.alibaba</groupId>
63-
<artifactId>easyexcel</artifactId>
57+
<groupId>cn.hutool</groupId>
58+
<artifactId>hutool-jwt</artifactId>
6459
</dependency>
6560
</dependencies>
6661

common/plugin/concurrent/pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>top.cadecode</groupId>
7+
<artifactId>uni-boot-common-plugin</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>uni-boot-common-plugin-concurrent</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>top.cadecode</groupId>
17+
<artifactId>uni-boot-common-core</artifactId>
18+
</dependency>
19+
<!--ttl-->
20+
<dependency>
21+
<groupId>com.alibaba</groupId>
22+
<artifactId>transmittable-thread-local</artifactId>
23+
</dependency>
24+
<!--dynamicTp-->
25+
<dependency>
26+
<groupId>org.dromara.dynamictp</groupId>
27+
<artifactId>dynamic-tp-core</artifactId>
28+
</dependency>
29+
<!--dynamicTp 邮件通知-->
30+
<dependency>
31+
<groupId>org.dromara.dynamictp</groupId>
32+
<artifactId>dynamic-tp-spring-boot-starter-extension-notify-email</artifactId>
33+
</dependency>
34+
</dependencies>
35+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package top.cadecode.uniboot.common.plugin.concurrent.config;
2+
3+
import org.dromara.dynamictp.core.spring.EnableDynamicTp;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
/**
7+
* DynamicTp Config
8+
*
9+
* @author Cade Li
10+
* @since 2023/6/9
11+
*/
12+
@EnableDynamicTp
13+
@Configuration
14+
public class DynamicTpConfig {
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package top.cadecode.uniboot.common.plugin.concurrent.util;
2+
3+
import com.alibaba.ttl.TtlCallable;
4+
import com.alibaba.ttl.TtlRunnable;
5+
import com.alibaba.ttl.threadpool.TtlExecutors;
6+
7+
import java.util.concurrent.Callable;
8+
import java.util.concurrent.Executor;
9+
10+
/**
11+
* Transmittable 工具类
12+
*
13+
* @author Cade Li
14+
* @since 2023/6/9
15+
*/
16+
public class TransmitUtil {
17+
18+
// 包装线程池或者 Runnable/Callable
19+
20+
public static Executor wrap(Executor executor) {
21+
return TtlExecutors.getTtlExecutor(executor);
22+
}
23+
24+
public static TtlRunnable wrap(Runnable runnable) {
25+
return TtlRunnable.get(runnable);
26+
}
27+
28+
public static <T> TtlCallable<T> wrap(Callable<T> callable) {
29+
return TtlCallable.get(callable);
30+
}
31+
}

common/plugin/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<module>datasource</module>
2121
<module>mybatis</module>
2222
<module>swagger</module>
23+
<module>concurrent</module>
2324
</modules>
2425

2526
</project>

dependencies/pom.xml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<spring-boot.version>2.5.4</spring-boot.version>
2525
<lombok.version>1.18.24</lombok.version>
2626
<mapstruct.version>1.4.2.Final</mapstruct.version>
27-
<hutool.vsersion>5.8.0</hutool.vsersion>
27+
<hutool.vsersion>5.8.1</hutool.vsersion>
2828
<guava.vsersion>31.0.1-jre</guava.vsersion>
2929
<vavr.vsersion>1.0.0-alpha-4</vavr.vsersion>
3030
<mica-auto.version>2.3.2</mica-auto.version>
@@ -38,7 +38,7 @@
3838
<dynamic-ds.version>3.6.0</dynamic-ds.version>
3939
<sba.version>2.6.11</sba.version>
4040
<ttl.version>2.12.2</ttl.version>
41-
<dynamic-tp.version>1.1.0</dynamic-tp.version>
41+
<dynamic-tp.version>1.1.3</dynamic-tp.version>
4242
<easyexcel.version>3.1.1</easyexcel.version>
4343
</properties>
4444

@@ -61,12 +61,6 @@
6161
<artifactId>mapstruct-processor</artifactId>
6262
<version>${mapstruct.version}</version>
6363
</dependency>
64-
<!--hutool-->
65-
<dependency>
66-
<groupId>cn.hutool</groupId>
67-
<artifactId>hutool-all</artifactId>
68-
<version>${hutool.vsersion}</version>
69-
</dependency>
7064
<!--guava-->
7165
<dependency>
7266
<groupId>com.google.guava</groupId>
@@ -79,18 +73,35 @@
7973
<artifactId>vavr</artifactId>
8074
<version>${vavr.vsersion}</version>
8175
</dependency>
76+
<!--hutool-->
77+
<dependency>
78+
<groupId>cn.hutool</groupId>
79+
<artifactId>hutool-core</artifactId>
80+
</dependency>
81+
<dependency>
82+
<groupId>cn.hutool</groupId>
83+
<artifactId>hutool-extra</artifactId>
84+
</dependency>
8285
</dependencies>
8386

8487
<dependencyManagement>
8588
<dependencies>
86-
<!--SpringBoot 依赖-->
89+
<!--SpringBoot 依赖版本控制-->
8790
<dependency>
8891
<groupId>org.springframework.boot</groupId>
8992
<artifactId>spring-boot-dependencies</artifactId>
9093
<version>${spring-boot.version}</version>
9194
<type>pom</type>
9295
<scope>import</scope>
9396
</dependency>
97+
<!--hutool 依赖版本控制-->
98+
<dependency>
99+
<groupId>cn.hutool</groupId>
100+
<artifactId>hutool-bom</artifactId>
101+
<version>${hutool.vsersion}</version>
102+
<type>pom</type>
103+
<scope>import</scope>
104+
</dependency>
94105
<!--mica-auto,自动化 spring.factories-->
95106
<dependency>
96107
<groupId>net.dreamlu</groupId>
@@ -159,13 +170,13 @@
159170
</dependency>
160171
<!--dynamicTp-->
161172
<dependency>
162-
<groupId>cn.dynamictp</groupId>
163-
<artifactId>dynamic-tp-spring-boot-starter-common</artifactId>
173+
<groupId>org.dromara.dynamictp</groupId>
174+
<artifactId>dynamic-tp-core</artifactId>
164175
<version>${dynamic-tp.version}</version>
165176
</dependency>
166177
<!--dynamicTp 邮件通知-->
167178
<dependency>
168-
<groupId>cn.dynamictp</groupId>
179+
<groupId>org.dromara.dynamictp</groupId>
169180
<artifactId>dynamic-tp-spring-boot-starter-extension-notify-email</artifactId>
170181
<version>${dynamic-tp.version}</version>
171182
</dependency>

framework/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,14 @@
3737
<groupId>top.cadecode</groupId>
3838
<artifactId>uni-boot-common-plugin-cache</artifactId>
3939
</dependency>
40+
<dependency>
41+
<groupId>top.cadecode</groupId>
42+
<artifactId>uni-boot-common-plugin-concurrent</artifactId>
43+
</dependency>
44+
<!--http-->
45+
<dependency>
46+
<groupId>cn.hutool</groupId>
47+
<artifactId>hutool-http</artifactId>
48+
</dependency>
4049
</dependencies>
4150
</project>

framework/src/main/java/top/cadecode/uniboot/framework/config/ThreadPoolConfig.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package top.cadecode.uniboot.framework.config;
22

3-
import com.dtp.core.DtpRegistry;
4-
import com.dtp.core.spring.EnableDynamicTp;
3+
import lombok.RequiredArgsConstructor;
54
import lombok.extern.slf4j.Slf4j;
65
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
76
import org.springframework.context.annotation.Bean;
87
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.core.task.AsyncTaskExecutor;
99
import org.springframework.scheduling.annotation.AsyncConfigurer;
1010
import org.springframework.scheduling.annotation.EnableAsync;
1111
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -14,19 +14,22 @@
1414

1515
import java.util.concurrent.Executor;
1616

17+
1718
/**
1819
* 线程池设置
1920
*
2021
* @author Cade Li
2122
* @date 2023/3/15
2223
*/
2324
@Slf4j
24-
@EnableDynamicTp
25+
@RequiredArgsConstructor
2526
@EnableAsync
2627
@EnableScheduling
2728
@Configuration
2829
public class ThreadPoolConfig {
2930

31+
private final AsyncTaskExecutor asyncExecutor;
32+
3033
/**
3134
* Spring 定时任务线程池
3235
*/
@@ -50,7 +53,7 @@ public AsyncConfigurer asyncConfigurer() {
5053
return new AsyncConfigurer() {
5154
@Override
5255
public Executor getAsyncExecutor() {
53-
return DtpRegistry.getDtpExecutor("asyncExecutor");
56+
return asyncExecutor;
5457
}
5558

5659
@Override

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@
6262
<artifactId>uni-boot-common-plugin-swagger</artifactId>
6363
<version>${uni.version}</version>
6464
</dependency>
65+
<dependency>
66+
<groupId>top.cadecode</groupId>
67+
<artifactId>uni-boot-common-plugin-concurrent</artifactId>
68+
<version>${uni.version}</version>
69+
</dependency>
6570
<dependency>
6671
<groupId>top.cadecode</groupId>
6772
<artifactId>uni-boot-framework</artifactId>

0 commit comments

Comments
 (0)