当前位置:网站首页>Thread forced join, thread forced join application scenarios
Thread forced join, thread forced join application scenarios
2022-07-01 18:35:00 【Hao Kai】
Thread forced join 、 Threads are forced to join the application scenario
Thread forced join join
- join Merge threads , After this thread has finished executing , Execute other threads , Other threads are blocking
- Thread queue jumping
- In the code block of the main thread , If you come across join Method , At this time, the main thread will block , Wait for the child thread to end , And go on with it join Code block after
Code
package testthread;
public class TestJoin {
public static void main(String[] args) throws InterruptedException {
// Start thread
Thread t = new Thread("vip") {
@Override
public void run() {
int countDown = 10;
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
countDown--;
System.out.println(Thread.currentThread().getName() + System.currentTimeMillis());
if (countDown <= 0) {
break;
}
}
}
};
//t coming , But not yet join, here , It is the main thread and t Threads execute alternately
t.start();
// The main thread
for (int i = 0; i < 20; i++) {
if (i == 10) {
t.join();// perform join Instead of alternate execution , Main thread blocking , Only execute t Threads , After execution, execute the main thread
}
System.out.println("main" + System.currentTimeMillis());
}
}
/* Output : main1644572688188 main1644572688188 main1644572688188 main1644572688188 main1644572688188 main1644572688188 main1644572688188 main1644572688188 main1644572688188 main1644572688188 vip1644572689190 vip1644572690191 vip1644572691206 vip1644572692217 vip1644572693224 vip1644572694239 vip1644572695250 vip1644572696264 vip1644572697264 vip1644572698277 main1644572698278 main1644572698278 main1644572698278 main1644572698278 main1644572698278 main1644572698278 main1644572698278 main1644572698278 main1644572698278 main1644572698278 */
}
边栏推荐
- js如何将带有分割符的字符串转化成一个n维数组
- Fix the problem that easycvr device video cannot be played
- February 16, 2022 Daily: graph neural network self training method under distribution and migration
- Mysql database design
- Android development interview was badly hit in 3 years, and now the recruitment technical requirements are so high?
- A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database
- Localization through custom services in the shuttle application
- [source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
- Set the style of QT property sheet control
- Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
猜你喜欢
Distributed task queue: Celery usage record
What are the legal risks of NFT brought by stars such as curry and O'Neill?
t10_ Adapting to Market Participantsand Conditions
Data query language (DQL)
LeetCode 148. Sort linked list
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
Cassette helicopter and alternating electric field magnetic manometer DPC
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
随机推荐
Domestic spot silver should be understood
D. Yet Another Minimization Problem
Glidefast consulting was selected as the elite partner of servicenow in 2022
信度系数低怎么办?信度系数具体怎么算?
MySQL + JSON = King fried
February 16, 2022 Daily: graph neural network self training method under distribution and migration
Happy new year | 202112 monthly summary
Function, condition, regular expression
EasyCVR设备录像出现无法播放现象的问题修复
Nielseniq found that 60% of the re launched products had poor returns
Step size of ode45 and reltol abstol
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
Is online stock account opening safe? Is it reliable?
Samba basic usage
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
Develop those things: add playback address authentication to easycvr platform
Classpath classpath
必看,时间序列分析
期货账户的资金安全吗?怎么开户?
The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup