当前位置:网站首页>多线程——线程池
多线程——线程池
2022-07-26 14:03:00 【看小虫子】
线程池
线程池的思路
提前创建好多个线程,放入线程池中,使用时直接取,使用完放回池中;
可以避免重复创建和销毁,实现重复利用;
好处
1,提高响应速度,减少创建新线程的时间
2,降低资源消耗,重复利用线程池中线程,不需要每次都创建
3,便于线程管路
corePoolSize :核心池大小
package TestThreadCommunication;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
//测试线程池
public class TestThreadPool {
public static void main(String[] args) {
//1,创建线程池
//newFixedThreadPool参数为线程池大小
ExecutorService service= Executors.newFixedThreadPool(10);
service.execute(new MyThread());
service.execute(new MyThread());
service.execute(new MyThread());
service.execute(new MyThread());
//2,关闭连接
service.shutdown();
}
}
class MyThread implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
边栏推荐
- JS timer realizes the countdown and jumps to the login page
- Force deduction ----- the number of words in the string
- Explain four interesting NPM usages with charts
- 基于用户画像的在线健康社区用户流失预测研究
- mysql5.7通过文件zip方式安装-九五小庞
- Book download | introduction to lifelong supervised learning in 2022, CO authored by meta AI, CMU and other scholars, 171 Pages pdf
- Pytoch learning notes (II) the use of neural networks
- 向路由组件传递参数
- JS submit the form to determine whether the user name and password are empty
- Official announcement! Edweisen group and Baidu xirang reached a deep co creation cooperation
猜你喜欢

Disease knowledge discovery based on spo semantic triples

Large and small end mode

MySQL's practice of SQL analysis and optimization from the index principle

Videojs to canvas pause, play, switch video

@A thousand lines of work, ride the cloud together!

Solve the problem that JUnit of idea console cannot be input with scanner

Meeting seating and submission for approval of OA project

LCL三相pwm整流器(逆变器)

【论文阅读】GRAW+:A Two-View Graph Propagation Method With Word Coupling for Readability Assessment

基于标签嵌入注意力机制的多任务文本分类模型
随机推荐
I. creation and constraint of MySQL table
ISCC2021 LOCKK题解
@A thousand lines of work, ride the cloud together!
Multi task text classification model based on tag embedded attention mechanism
聚力打造四个“高地”,携手合作伙伴共铸国云!
Synchronization mechanism of go (sync.mutex)
Ten thousand words long article, talking about the blueprint of enterprise digital modeling
A survey of machine learning based technology term recognition
基于多特征的技术融合关系预测及其价值评估
Joint entity and event extraction model based on multi task deep learning
JS page turning, kkpager.js page turning
向路由组件传递参数
Videojs to canvas pause, play, switch video
大小端模式
Redis learning notes
Completable future practical usage
Detailed explanation of alter field of MySQL Foundation
Book download | introduction to lifelong supervised learning in 2022, CO authored by meta AI, CMU and other scholars, 171 Pages pdf
Segmentation fault (core dumped)
How can red star Macalline design cloud upgrade the traditional home furnishing industry in ten minutes to produce film and television level interior design effects