当前位置:网站首页>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();
}
}
边栏推荐
- When grep looks for a process, it ignores the grep process itself
- 百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
- LeetCode. Sword finger offer 62 The last remaining number in the circle
- 公钥\私人 ssh避password登陆
- npm install 编译时报“Cannot read properties of null (reading ‘pickAlgorithm‘)“
- JS how to quickly create an array with length n
- AcWing 345. Cattle station solution (nature and multiplication of Floyd)
- Mysqlbackup restores specific tables
- 使用nodejs完成判断哪些项目打包+发版
- Get to know MySQL for the first time
猜你喜欢

AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)

The difference between Tansig and logsig. Why does BP like to use Tansig

Ros Learning (23) Action Communication Mechanism

Shell script quickly counts the number of lines of project code

ROS学习(24)plugin插件

AcWing 361. 观光奶牛 题解(spfa求正环)

Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins

Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter

Box stretch and pull (left-right mode)

Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
随机推荐
Appium foundation - appium inspector positioning tool (I)
MySQL's most basic select statement
AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
Reptile practice (VI): novel of climbing pen interesting Pavilion
Use nodejs to determine which projects are packaged + released
Yiwen takes you into [memory leak]
Let's see how to realize BP neural network in Matlab toolbox
The cradle of eternity
POJ 3177 redundant paths POJ 3352 road construction (dual connection)
String to date object
Modify the system time of Px4 flight control
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
爬虫实战(六):爬笔趣阁小说
Comparison of picture beds of free white whoring
[unique] what is the [chain storage structure]?
The use of video in the wiper component causes full screen dislocation
AcWing 1142. Busy urban problem solving (minimum spanning tree)
盒子拉伸拉扯(左右模式)
鼠标右键 自定义