当前位置:网站首页>Alibaba tip: it is better to create threads manually
Alibaba tip: it is better to create threads manually
2022-04-23 04:41:00 【Z-hhhhh】
Original creation method
ExecutorService executorService = Executors.newFixedThreadPool(threadNum);
Ali's plug-in tips : Creating threads manually works well
I looked at the explanation : It is easy to cause OOM, As it happens , I had this problem before .
So I used the way recommended by Ali to wear threads
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("thread-call-runner-%d").build();
ThreadPoolExecutor executor = new ThreadPoolExecutor(threadNum, threadNum + 2, 500L, TimeUnit.MICROSECONDS, new LinkedBlockingDeque<>(), threadFactory);
The packages that need to be imported manually
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.TimeUnit;
ThreadPoolExecutor The parameters of are detailed as follows
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory,
RejectedExecutionHandler handler)
corePoolSize => Number of core threads in thread pool
maximumPoolSize => Maximum number of thread pools
keepAliveTime => Idle thread lifetime
unit => Time unit
workQueue => Buffer queue used by thread pool
threadFactory => Thread pool creates the factory used by threads
handler => The processing strategy of the thread pool to reject the task
Alibaba Java Coding Guidelines It's really a good thing , You deserve it
Add something extra :
import com.google.common.util.concurrent.ThreadFactoryBuilder;
The problem is due to the lack of dependencies
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1-jre</version>
</dependency>
版权声明
本文为[Z-hhhhh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220559122200.html
边栏推荐
- 【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
- Experience summary and sharing of the first prize of 2021 National Mathematical Modeling Competition
- AWS EKS 部署要点以及控制台与eksctl创建的差异
- 520.检测大写字母
- 2019 is coming to an end, the longest day.
- 229. Find mode II
- Use recyclerview to realize left-right side-by-side classification selection
- 383. Ransom letter
- leetcode003--判断一个整数是否为回文数
- Leetcode002 -- inverts the numeric portion of a signed integer
猜你喜欢
简单的拖拽物体到物品栏
第四章 --- 了解标准设备文件、过滤器和管道
IDE idea automatic compilation and configuration of on update action and on frame deactivation
Shanghai Hangxin technology sharing 𞓜 overview of safety characteristics of acm32 MCU
Flink's important basics
2021数学建模国赛一等奖经验总结与分享
Jetpack 之 LifeCycle 组件使用详解
针对NFT的网络钓鱼
C language: Advanced pointer
MYSQL查询至少连续n天登录的用户
随机推荐
A new method for evaluating the quality of metagenome assembly - magista
mysql ,binlog 日志查询
test
[timing] empirical evaluation of general convolution and cyclic networks for sequence modeling based on TCN
Code007 -- determine whether the string in parentheses matches
Go reflection - go language Bible learning notes
Coinbase:关于跨链桥的基础知识、事实和统计数据
Coinbase: basic knowledge, facts and statistics about cross chain bridge
Bacterial infection and antibiotic use
Innovative practice of short video content understanding and generation technology in meituan
Druid -- JDBC tool class case
HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力
Fusobacterium -- symbiotic bacteria, opportunistic bacteria, oncobacterium
QML advanced (V) - realize all kinds of cool special effects through particle simulation system
Installation and use of Apache bench (AB pressure test tool)
Supplement 14: cmake practice project notes (to be continued 4 / 22)
Recommended scheme for national production of electronic components of wireless keyboard
AWS eks add cluster user or Iam role
Effects of antibiotics on microbiome and human health
RC低通滤波器的逆系统