当前位置:网站首页>Multithreading - thread pool
Multithreading - thread pool
2022-07-26 14:11:00 【Look at the bugs】
Thread pool
Thread pool idea
Create many threads ahead of time , Put it in the thread pool , Direct access during use , Put it back into the pool after use ;
It can avoid repeated creation and destruction , Achieve reuse ;
benefits
1, Improve response time , Reduce the time to create new threads
2, Reduce resource consumption , Reuse threads in the thread pool , You don't need to create... Every time
3, Easy to thread pipeline
corePoolSize : Core pool size
package TestThreadCommunication;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
// Test thread pool
public class TestThreadPool {
public static void main(String[] args) {
//1, Creating a thread pool
//newFixedThreadPool The parameter is the thread pool size
ExecutorService service= Executors.newFixedThreadPool(10);
service.execute(new MyThread());
service.execute(new MyThread());
service.execute(new MyThread());
service.execute(new MyThread());
//2, Close the connection
service.shutdown();
}
}
class MyThread implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
边栏推荐
- 图书下载 | 2022年《终身监督学习导论》Meta AI、CMU等学者合著,171页PDF
- 12437 words, take you to explore the principle of RPC communication
- Construction practice of pipeline engine of engineering efficiency ci/cd
- ISCC2021 LOCKK题解
- Leetcode36 effective Sudoku
- POM file details
- 基址寻址和变址寻址区别
- Red * is added to the input box to indicate mandatory items
- Difference between base addressing and index addressing
- Job 7.25 sorting and searching
猜你喜欢

@千行百业,一起乘云而上!

循环队列(c语言实现)

JS download files, filesaver.js export txt and Excel files

聚力打造四个“高地”,携手合作伙伴共铸国云!

Jzoffer (array; string; linked list)

~6. CCF 2021-09-1 array derivation

DP sword finger offer II 100. sum of minimum paths in triangle

C语言_结构体和数组的结合

融合多自然语言处理任务的中医辅助诊疗方案研究——以糖尿病为例

Circular queue (implemented in C language)
随机推荐
C语言贪吃蛇-链表和指针练习
Pytoch learning notes (II) the use of neural networks
The difference between V-model and.Sync modifier
Mlx90640 infrared thermal imager temperature sensor module development notes (6)
Synchronization mechanism of go (sync.mutex)
使用cpolar建立一个商业网站(申请网站安全证书)
Share 44 JS problems, and half of them are masters
redis学习笔记
C language Snake linked list and pointer practice
技术分享 | 需要小心配置的 gtid_mode
什么是Restful风格以及它的四种具体实现形式
Joint entity and event extraction model based on multi task deep learning
Prediction and value evaluation of technology fusion relationship based on multiple features
ISCC2021 LOCKK题解
uni-app从创建到运行到微信开发者工具
[paper reading] raw+:a two view graph propagation method with word coupling for readability assessment
Native JS get transform value x y z and rotate rotation angle
OA项目之我的会议
Circular queue (implemented in C language)
JS page turning, kkpager.js page turning