当前位置:网站首页>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();
}
}
边栏推荐
- AcWing 344. Solution to the problem of sightseeing tour (Floyd finding the minimum ring of undirected graph)
- Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
- CISP-PTE实操练习讲解(二)
- Basic introduction and use of dvajs
- 一文带你走进【内存泄漏】
- Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror
- 盒子拉伸拉扯(左右模式)
- Analyze "C language" [advanced] paid knowledge [End]
- sql中批量删除数据---实体中的集合
- 2022 system integration project management engineer examination knowledge point: Mobile Internet
猜你喜欢

ROS学习(21)机器人SLAM功能包——orbslam的安装与测试

微服务架构介绍

dvajs的基础介绍及使用

Analyze "C language" [advanced] paid knowledge [End]

Analyze "C language" [advanced] paid knowledge [i]

Appium automation test foundation uiautomatorviewer positioning tool

Make DIY welding smoke extractor with lighting

AcWing 1148. 秘密的牛奶运输 题解(最小生成树)

ROS learning (XIX) robot slam function package cartographer

新工作感悟~辞旧迎新~
随机推荐
Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror
2022/0524/bookstrap
uva 1401 dp+Trie
ROS learning (XIX) robot slam function package cartographer
微服务架构介绍
AcWing 345. 牛站 题解(floyd的性质、倍增)
AcWing 1142. Busy urban problem solving (minimum spanning tree)
PartyDAO如何在1年内把一篇推文变成了2亿美金的产品DAO
使用nodejs完成判断哪些项目打包+发版
The difference between Tansig and logsig. Why does BP like to use Tansig
AcWing 346. Solution to the problem of water splashing festival in the corridor (deduction formula, minimum spanning tree)
The cradle of eternity
ROS learning (24) plugin
Blue Bridge Cup 2022 13th provincial competition real topic - block painting
Box stretch and pull (left-right mode)
对C语言数组的再认识
Ds-5/rvds4.0 variable initialization error
初识MySQL
ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
C语言【23道】经典面试题【下】