当前位置:网站首页>Treadpoolconfig thread pool configuration in real projects
Treadpoolconfig thread pool configuration in real projects
2022-07-07 01:56:00 【Novice Zhang~】
package com.menglar.soap.item.common.config;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ThreadPoolExecutor;
/** * @program: soap-item_v2 * @description: Thread pool configuration * @author: ZhangRiTian * @create: 2021-10-25 09:24 */
@Configuration
@EnableAsync
public class TreadPoolConfig {
@Value("${threadpool.corePoolSize}")
private int corePoolSize;
@Value("${threadpool.maxPoolSize}")
private int maxPoolSize;
@Value("${threadpool.queueCapacity}")
private int queueCapacity;
@Value("${threadpool.keepAliveSeconds}")
private int keepAliveSeconds;
@Bean(name = "threadPoolTaskExecutor")
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
// Number of core thread pools , Method : Returns the number of available processors Java Number of virtual machines .
pool.setCorePoolSize(corePoolSize);
// Maximum number of threads
pool.setMaxPoolSize(maxPoolSize);
// Queue capacity of the thread pool
pool.setQueueCapacity(queueCapacity);
// The thread pool maintains the free time allowed for threads
pool.setKeepAliveSeconds(keepAliveSeconds);
// Prefix of thread name
pool.setThreadNamePrefix("this-excutor-menglar-");
// setRejectedExecutionHandler: When pool Already achieved max size When , How to deal with new tasks
// CallerRunsPolicy: Do not execute tasks in New Threads , Instead, it is executed by the thread of the caller
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
pool.initialize();
return pool;
}
/** * Exception handling in asynchronous tasks * */
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
// TODO Auto-generated method stub
return new SimpleAsyncUncaughtExceptionHandler();
}
}
边栏推荐
- HDU 4661 message passing (wood DP & amp; Combinatorics)
- AcWing 1142. Busy urban problem solving (minimum spanning tree)
- 刨析《C语言》【进阶】付费知识【完结】
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
- Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
- C language [23] classic interview questions [Part 2]
- Shell script quickly counts the number of lines of project code
- ROS learning (26) dynamic parameter configuration
- ROS学习(23)action通信机制
- 新工作感悟~辞旧迎新~
猜你喜欢
【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?
ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
ROS learning (22) TF transformation
2022/0524/bookstrap
Recognition of C language array
开发中对集合里面的数据根据属性进行合并数量时犯的错误
Today's question -2022/7/4 modify string reference type variables in lambda body
ROS learning (XIX) robot slam function package cartographer
微服务架构介绍
一文带你走进【内存泄漏】
随机推荐
How to use strings as speed templates- How to use String as Velocity Template?
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
Drag to change order
Box stretch and pull (left-right mode)
ROS learning (23) action communication mechanism
刨析《C语言》【进阶】付费知识【完结】
LeetCode. Sword finger offer 62 The last remaining number in the circle
golang 基础 —— 数据类型
制作带照明的DIY焊接排烟器
JS ES5也可以創建常量?
AcWing 904. 虫洞 题解(spfa求负环)
Use nodejs to determine which projects are packaged + released
Mysqlbackup restores specific tables
Input and output of C language pointer to two-dimensional array
Scenario practice: quickly build wordpress blog system based on function calculation
对C语言数组的再认识
字符串的相关编程题
mysqlbackup 还原特定的表
Modify the system time of Px4 flight control
mongodb查看表是否导入成功