当前位置:网站首页>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());
}
}
边栏推荐
猜你喜欢

php使用sqlserver

GDB common commands

Solve the problem that JUnit of idea console cannot be input with scanner
![[GYCTF2020]FlaskApp](/img/ee/dcb42617af4a0e41657f6cf7095feb.png)
[GYCTF2020]FlaskApp

Uni app from creation to operation to wechat developer tool

敏捷开发与DevOps的对比

ISCC2021 LOCKK题解

MLX90640 红外热成像仪测温传感器模块开发笔记(六)

Disease knowledge discovery based on spo semantic triples

万字长文,浅谈企业数字化建模蓝图
随机推荐
MLX90640 红外热成像仪测温传感器模块开发笔记(六)
@千行百业,一起乘云而上!
Plato farm is expected to further expand its ecosystem through elephant swap
Multithreaded completable future usage
UDP多线程在线聊天
Comparison between agile development and Devops
基于标签嵌入注意力机制的多任务文本分类模型
redis学习笔记
[NOIP2003 普及组]栈
Flink SQL (III) connects to the external system system and JDBC
1-to-1 live broadcast source code - 1-to-1 voice chat source code
基于多任务深度学习的实体和事件联合抽取模型
低功耗多通道WFAS1431无线数据采集采发仪使用流程说明
Plato Farm有望通过Elephant Swap,进一步向外拓展生态
"Baget" takes you one minute to build your own private nuget server
Completable future practical usage
大脑带来的启发:深度神经网络优化中突触整合原理介绍
『SignalR』.NET使用 SignalR 进行实时通信初体验
POM文件详解
JS submit the form to determine whether the user name and password are empty