当前位置:网站首页>如何让主线程等待子线程执行完毕后再执行
如何让主线程等待子线程执行完毕后再执行
2022-06-26 06:05:00 【明明就很安静】
总结三个方法:
(1)join方法,直接将每个线程都join进去即可。
(2)countdownlatch,内部维持一个计数操作,通过cas算法保证操作的原子性,当线程执行完之后,调用countDown()方法,将计数减一,主线程调用countdownlatch对象的await()方法,将当前线程挂起,直到countdownlatch对象的计数为0,主线程执行。
(3)类似屏障的东西,当子线程执行完之后,调用CyclicBarrier对象的await()方法,直到指定数量的线程到达屏障之后,才会继续执行主线程。把每一个子线程比作&&符号的一个条件,那么只有到所有条件都满足时,才会执行主线程。
边栏推荐
- NPM private server problem of peanut shell intranet penetration mapping
- Prototype mode, Baa Baa
- Keepalived to achieve high service availability
- Force buckle 875 Coco, who likes bananas
- Redis multithreading and ACL
- Efk upgrade to Clickhouse log storage practice
- PyTorch混合精度原理及如何开启该方法
- Matching environment of ES6
- numpy.exp()
- University Information Management System
猜你喜欢
Factory method pattern, abstract factory pattern
Design and practice of low code real-time data warehouse construction system
A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~
Younger sister Juan takes you to learn JDBC -- two days' Sprint Day2
Selective Search for Object Recognition 论文笔记【图片目标分割】
ByteDance starts the employee's sudden wealth plan and buys back options with a large amount of money. Some people can earn up to 175%
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
数据治理工作的几种推进套路
Test depends on abstraction and does not depend on concrete
MySQL-07
随机推荐
How to use the tablet as the second extended screen of the PC
SQL Server 函数
COW读写复制机制在Linux,Redis ,文件系统中的应用
解决在win10下cmder无法使用find命令
技术Leader的思考技巧
Level signal and differential signal
Upgrading technology to art
SQL Server视图
MySQL-08
跨域的五种解决方案
Playing RTSP streaming video on Web pages (webrtc)
Thinking and summary of technical ability
Basic construction of SSM framework
A tragedy triggered by "yyyy MM DD" and vigilance before New Year's Day~
Library management system
Mongodb——使用Mongodb对字段中字符串内容进行截取,并进行分组统计
Redis multithreading and ACL
消息队列-功能、性能、运维对比
How to select and build a real-time data warehouse scheme
PyTorch混合精度原理及如何开启该方法