当前位置:网站首页>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 1142. Busy urban problem solving (minimum spanning tree)
- Add PDF Title floating window
- Appium基础 — Appium Inspector定位工具(一)
- AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
- Compile command line terminal swift
- HDU 4661 message passing (wood DP & amp; Combinatorics)
- The difference between Tansig and logsig. Why does BP like to use Tansig
- Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror
- 拖拽改变顺序
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
猜你喜欢
PartyDAO如何在1年内把一篇推文变成了2亿美金的产品DAO
dvajs的基础介绍及使用
JVM memory model
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
454 Baidu Mianjing 1
The cradle of eternity
制作带照明的DIY焊接排烟器
sql中批量删除数据---实体中的集合
鼠标右键 自定义
Analyze "C language" [advanced] paid knowledge [II]
随机推荐
New job insights ~ leave the old and welcome the new~
开发中对集合里面的数据根据属性进行合并数量时犯的错误
mysqlbackup 还原特定的表
POJ 3177 Redundant Paths POJ 3352 Road Construction(双连接)
ROS learning (21) robot slam function package -- installation and testing of orbslam
我如何编码8个小时而不会感到疲倦。
ROS learning (22) TF transformation
刨析《C语言》【进阶】付费知识【二】
Make DIY welding smoke extractor with lighting
The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
@Before, @after, @around, @afterreturning execution sequence
ROS learning (24) plugin
ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
Centos8 install MySQL 8.0 using yum x
ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
MySQL execution process and sequence
Long press the button to execute the function
ROS learning (23) action communication mechanism
How can I code for 8 hours without getting tired.
Compile command line terminal swift