当前位置:网站首页>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();
}
}
边栏推荐
- WCF基金会
- The cradle of eternity
- POJ 3177 redundant paths POJ 3352 road construction (dual connection)
- swiper组件中使用video导致全屏错位
- 百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
- 设置Wordpress伪静态连接(无宝塔)
- ROS learning (25) rviz plugin
- AcWing 904. Wormhole solution (SPFA for negative rings)
- Input and output of C language pointer to two-dimensional array
- AcWing 1140. Shortest network (minimum spanning tree)
猜你喜欢
Scenario practice: quickly build wordpress blog system based on function calculation
Appium foundation - appium inspector positioning tool (I)
mongodb查看表是否导入成功
蓝桥杯2022年第十三届省赛真题-积木画
ROS学习(24)plugin插件
Shell script quickly counts the number of lines of project code
Centos8 install MySQL 8.0 using yum x
shell脚本快速统计项目代码行数
一文带你走进【内存泄漏】
How did partydao turn a tweet into a $200million product Dao in one year
随机推荐
JS Es5 can also create constants?
MySQL's most basic select statement
Mysqlbackup restores specific tables
When grep looks for a process, it ignores the grep process itself
字符串转成日期对象
对C语言数组的再认识
ROS learning (21) robot slam function package -- installation and testing of orbslam
New job insights ~ leave the old and welcome the new~
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
uva 1401 dp+Trie
ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
454-百度面经1
Right mouse button customization
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
ROS learning (24) plugin
AcWing 361. 观光奶牛 题解(spfa求正环)
AcWing 1142. 繁忙的都市 题解(最小生成树)
ROS learning (22) TF transformation
CISP-PTE之命令注入篇
Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror