-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ed9d49
commit 626d5ec
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/github/flying/jeelite/modules/config/ThreadPoolConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.github.flying.jeelite.modules.config; | ||
|
||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.task.TaskExecutor; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
/** | ||
* 线程池配置 | ||
* | ||
*/ | ||
@Configuration | ||
public class ThreadPoolConfig { | ||
|
||
@Bean("taskExecutor") | ||
public TaskExecutor taskExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(10);//核心线程数 | ||
executor.setMaxPoolSize(20);//最大线程数 | ||
executor.setQueueCapacity(200);//缓冲队列容量 | ||
executor.setKeepAliveSeconds(60);//允许线程空闲的时间60秒:当超过了核心线程之外的线程在空闲时间到达之后会被销毁 | ||
executor.setWaitForTasksToCompleteOnShutdown(true);//线程池关闭的时候等待所有任务都完成 | ||
executor.setAwaitTerminationSeconds(60);//设置线程池关闭时,线程池中任务的等待时间,如果超过这个时间任务还没有关闭就强制关闭 | ||
executor.setThreadNamePrefix("taskExecutor-");//线程池名的前缀 | ||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());//拒绝策略 | ||
return executor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters