当前位置:网站首页>Thread application instance
Thread application instance
2022-07-02 19:16:00 【Sang Yinghao】
One . Wait timeout mode
scene : Wait for a period of time when calling a method , If this method can get results within a given time , Will return immediately , conversely , If timeout, return the default result .
Two . Database connection pool
Definition of connection pool : Constructor initializes the maximum limit of the connection , Maintain connections through a two-way queue , The caller needs to call fetchConnection(long) Method to specify how many milliseconds to timeout to get a connection , When the connection is used , Need to call releaseConnection(Connection) Method to put the connection back into the connection pool .
3、 ... and . Thread pool technology
3.1 Role of thread pool
face Thousands of people Service delivery hand over Into the clothing service device when , If you still use one service One Line The way of Cheng , Then it will gen Build tens of thousands remember Of Line cheng , this It's not a good choice , Because this will make the operating system switch thread context frequently , Increase the load of the system for no reason , The creation and extinction of threads require system resources , It also undoubtedly wastes system resources .Thread pool solves this problem well , It creates several threads in advance , And it can't be directly controlled by users to create threads
3.2 Advantages of thread pool
- Reduce resource consumption
- Improve response time
- Improve the manageability of threads
3.3 Several parameters in the thread pool
1: Number of core threads (corePoolSize)
The design of the number of core threads needs to be determined according to the processing time of the task and the number of tasks generated per second , for example : Performing a task requires 0.1 second , The system is... Percent 80 Every second of the time will produce 100 A mission , So if you want to be in 1 Finish this in seconds 100 A mission , Need 10 Threads , At this point, we can design the number of core threads as 10; Of course, the actual situation cannot be so average , So we usually follow 8020 Principle design is enough , Both according to percent 80 Design the number of core threads in the case of , The remaining percent 20 The maximum number of threads can be used to process ;
2: Task queue length (workQueue)
The length of task queue is generally designed as : Number of core threads / Execution time of single task *2 that will do ; For example, in the above scene , The number of core threads is designed as 10, The execution time of a single task is 0.1 second , The queue length can be designed as 200;
3: Maximum number of threads (maximumPoolSize)
The design of the maximum number of threads needs to refer to the conditions of the number of core threads , You also need to refer to the maximum number of tasks generated by the system per second : for example : In the above environment , If the maximum task generated by the system per second is 1000 individual , that , Maximum number of threads =( Maximum number of tasks - Task queue length )* Execution time of single task ; Both : Maximum number of threads =(1000-200)*0.1=80 individual ;
4: Maximum free time (keepAliveTime)
The design of this parameter completely refers to the system operating environment and hardware pressure setting , There is no fixed reference value , The user can set a reasonable value according to experience and the time interval of the task generated by the system ;
3.4 Thread pool workflow
3.5Executor and Executors The difference between
Executor Interface objects can perform our threading tasks ;
Executors Different methods of tool classes create different Thread pool , To meet the needs of the business .
ExecutorService Interface inherited Executor Interface and extended , More ways , We can get the execution status of the task and the return value of the task .
3.6 Do you know how to create a thread pool ?
ThreadPoolExecutor
边栏推荐
- Fastdfs installation
- Excel finds the same value in a column, deletes the row or replaces it with a blank value
- Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5
- 新加坡暑假旅游攻略:一天玩转新加坡圣淘沙岛
- Mysql高级篇学习总结6:索引的概念及理解、B+树产生过程详解、MyISAM与InnoDB的对比
- Yunna | why use the fixed asset management system and how to enable it
- 新手必看,点击两个按钮切换至不同的内容
- 【ERP软件】ERP体系二次开发有哪些危险?
- 高级性能测试系列《24. 通过jdbc执行sql脚本》
- UML class diagram
猜你喜欢

Novice must see, click two buttons to switch to different content

Markdown基础语法
![[0701] [paper reading] allowing data imbalance issue with perforated input during influence](/img/c7/9b7dc4b4bda4ecfe07aec1367fe059.png)
[0701] [paper reading] allowing data imbalance issue with perforated input during influence

仿京东放大镜效果(pink老师版)

Tutorial (5.0) 09 Restful API * fortiedr * Fortinet network security expert NSE 5

Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5

思维意识转变是施工企业数字化转型成败的关键

全链路数字化转型下,零售企业如何打开第二增长曲线

【JVM调优实战100例】02——虚拟机栈与本地方法栈调优五例

MySQL advanced learning summary 7: MySQL data structure - Comparison of hash index, AVL tree, B tree and b+ tree
随机推荐
R语言dplyr包rowwise函数、mutate函数计算dataframe数据中多个数据列在每行的最大值、并生成行最大值对应的数据列(row maximum)
Processing strategy of message queue message loss and repeated message sending
Tutorial (5.0) 10 Troubleshooting * fortiedr * Fortinet network security expert NSE 5
【JVM调优实战100例】03——JVM堆调优四例
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
【ERP软件】ERP体系二次开发有哪些危险?
Tips for material UV masking
Introduction to the paper | application of machine learning in database cardinality estimation
Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent
MySQL advanced learning summary 7: MySQL data structure - Comparison of hash index, AVL tree, B tree and b+ tree
第一次去曼谷旅游怎么玩?这份省钱攻略请收好
虚拟机初始化脚本, 虚拟机相互免秘钥
机器学习笔记 - 时间序列预测研究:法国香槟的月销量
Page title component
Mysql高级篇学习总结6:索引的概念及理解、B+树产生过程详解、MyISAM与InnoDB的对比
[100 cases of JVM tuning practice] 01 - introduction of JVM and program counter
LightGroupButton* sender = static_ cast<LightGroupButton*>(QObject::sender());
#gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management
Installation of thingsboard, an open source IOT platform