3 Commits

Author SHA1 Message Date
wonder d56e55a038 📝Docs: [hutool-core-config] Completed 2025-11-10 21:59:41 +08:00
wonder 8819b8481e 📝Docs: [executor-service-config] Completed 2025-11-10 21:41:23 +08:00
wonder fa4d6e0549 📝Docs: [basic-async-config] Completed 2025-11-10 18:59:10 +08:00
3 changed files with 34 additions and 42 deletions
+30 -1
View File
@@ -1 +1,30 @@
https://doc.hutool.cn/pages/ExecutorBuilder # spring-boot-threadpool-demo
> 📚 适用于 SpringBoot 的多种线程池实现
**注意:Main 分支不包含具体实现,具体实现在项目的不同分支上**
## 分支大纲
### 分支 1: `basic-async-config`
> ✅ Completed
**主题:基础 @Async 注解方式**
- 实现简单的异步任务执行
- 配置基本的线程池参数
- 配置拒绝策略
- 测试异步方法调用
### 分支 2: `executor-service-config`
> ✅ Completed
- Java 自带线程池
- 无限队列长度
### 分支 3: `hutool-core-config`
> ✅ Completed
- 简单易用的 Hutool 工具类
-6
View File
@@ -23,12 +23,6 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>5.8.31</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
@@ -1,42 +1,11 @@
package cn.hezhaohui.threadpool; package cn.hezhaohui.threadpool;
import cn.hutool.core.thread.ExecutorBuilder; import org.springframework.boot.SpringApplication;
import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.concurrent.ArrayBlockingQueue; @SpringBootApplication
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Slf4j
public class ThreadPoolApplication { public class ThreadPoolApplication {
public static void main(String[] args) { public static void main(String[] args) {
ExecutorBuilder builder = new ExecutorBuilder(); SpringApplication.run(ThreadPoolApplication.class, args);
ThreadPoolExecutor executor = builder
.setCorePoolSize(5)
.setMaxPoolSize(10)
.setKeepAliveTime(0)
.setHandler(new RejectedExecutionHandler(){
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
log.info(r.toString());
}
})
.setWorkQueue(new ArrayBlockingQueue<>(100))
.build();
for (int i = 1; i <= 1000; i++) {
executor.execute(() -> {
log.info("Hello");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}
executor.shutdown();
} }
} }