Skip to content

Commit a5228c8

Browse files
committed
修改线程池配置
1 parent c393dce commit a5228c8

File tree

3 files changed

+44
-33
lines changed

3 files changed

+44
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/springboot-dubbo-web/src/test/
66
/springboot-dubbo-web/src/main/resources/rebel.xml
77
/springboot-dubbo-service/src/test/
8+
/.idea/
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.lzq.web.config;
2+
3+
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.scheduling.annotation.AsyncConfigurer;
6+
import org.springframework.scheduling.annotation.EnableAsync;
7+
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
8+
9+
import java.util.concurrent.Executor;
10+
11+
/**
12+
* @author :LZQ
13+
* @description:TODO
14+
* @date :2021/9/24 9:17
15+
*/
16+
@Configuration
17+
@EnableAsync
18+
public class AsyncTaskConfig implements AsyncConfigurer {
19+
@Override
20+
public Executor getAsyncExecutor() {
21+
ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
22+
//设置核心线程数
23+
threadPool.setCorePoolSize(10);
24+
//设置最大线程数
25+
threadPool.setMaxPoolSize(100);
26+
//线程池所使用的缓冲队列
27+
threadPool.setQueueCapacity(10);
28+
//等待任务在关机时完成--表明等待所有线程执行完
29+
threadPool.setWaitForTasksToCompleteOnShutdown(true);
30+
// 等待时间 (默认为0,此时立即停止),并没等待xx秒后强制停止
31+
threadPool.setAwaitTerminationSeconds(60);
32+
// 线程名称前缀
33+
threadPool.setThreadNamePrefix("ScreenShot-Async-");
34+
// 初始化线程
35+
threadPool.initialize();
36+
return threadPool;
37+
}
38+
39+
@Override
40+
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
41+
return null;
42+
}
43+
}

springboot-dubbo-web/src/main/java/com/lzq/web/config/CustomMultiThreadingConfig.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)