Skip to content

Commit

Permalink
配置@async异步任务的线程池
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc87112 committed Sep 14, 2021
1 parent ee78526 commit 0bfbf65
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions 2.x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,17 @@

### 任务管理

**定时任务**

- [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1)
- [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2)
- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3)
- [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4)

**异步任务*

- [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5)
- [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6)


### 常见问题
Expand Down
5 changes: 5 additions & 0 deletions 2.x/README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@

### 任务管理

**定时任务**

- [Spring Boot 2.x基础教程:使用@Scheduled实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-1)
- [Spring Boot 2.x基础教程:使用Elastic Job实现定时任务](https://blog.didispace.com/spring-boot-learning-2-7-2)
- [Spring Boot 2.x基础教程:使用Elastic Job的分片配置提高执行效率](https://blog.didispace.com/spring-boot-learning-2-7-3)
- [Spring Boot 2.x基础教程:使用Elastic Job的namespace防止任务名冲突](https://blog.didispace.com/spring-boot-learning-2-7-4)

**异步任务*

- [Spring Boot 2.x基础教程:使用@Async实现异步任务](https://blog.didispace.com/spring-boot-learning-2-7-5)
- [Spring Boot 2.x基础教程:配置@Async异步任务的线程池](https://blog.didispace.com/spring-boot-learning-2-7-6)

### 常见问题

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

@Slf4j
@Component
Expand Down
9 changes: 9 additions & 0 deletions 2.x/chapter7-6/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spring.task.execution.pool.core-size=2
spring.task.execution.pool.max-size=5
spring.task.execution.pool.queue-capacity=10
spring.task.execution.pool.keep-alive=60s
spring.task.execution.pool.allow-core-thread-timeout=true
spring.task.execution.thread-name-prefix=task-

spring.task.execution.shutdown.await-termination=false
spring.task.execution.shutdown.await-termination-period=30s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.boot.test.context.SpringBootTest;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

@Slf4j
@SpringBootTest
Expand All @@ -16,7 +15,7 @@ public class Chapter76ApplicationTests {
private AsyncTasks asyncTasks;

@Test
public void test() throws Exception {
public void test1() throws Exception {
long start = System.currentTimeMillis();

CompletableFuture<String> task1 = asyncTasks.doTaskOne();
Expand Down
6 changes: 5 additions & 1 deletion 2.x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
<module>chapter7-3</module> <!-- 7-3 使用Elastic Job的分片配置 -->
<module>chapter7-4</module> <!-- 7-4 使用Elastic Job的namespace防止任务名冲突 -->
<module>chapter7-5</module> <!-- 7-5 使用@Async实现异步任务 -->
<module>chapter7-6</module> <!-- 7-6 @Async异步任务的线程池配置 -->
<module>chapter7-6</module> <!-- 7-6 配置@Async异步任务的线程池 -->
<!--7-7 @Async异步任务的线程池隔离-->

<!-- 安全控制 -->
<module>chapter8-1</module> <!-- Spring Security快速入门 -->

</modules>
</project>

0 comments on commit 0bfbf65

Please sign in to comment.