当前位置:网站首页>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 */
}
边栏推荐
- Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
- 12. Design of power divider for ads usage record
- Software construction scheme of smart factory collaborative management and control application system
- Session layer of csframework, server and client (1)
- Mujoco XML modeling
- [noip2015] jumping stone
- Irradiance, Joule energy, exercise habits
- Sanfeng cloud 0215 I often use
- L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
- Definition of rotation axis in mujoco
猜你喜欢

Cloud computing - make learning easier

Static timing analysis (STA) in ic/fpga design

Mujoco XML modeling

PTA year of birth

What are the legal risks of NFT brought by stars such as curry and O'Neill?

. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes

2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers

Penetration practice vulnhub range Tornado

Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)

Explain in detail the process of realizing Chinese text classification by CNN
随机推荐
Develop those things: add playback address authentication to easycvr platform
Three dimensional anti-terrorism Simulation Drill deduction training system software
Operating system interview assault
Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
Blue Bridge Cup real problem: word analysis
12种数据量纲化处理方式
The latest intelligent factory MES management system software solution
Win10+vs2019 Community Edition compiling OpenSSL
Vue uses keep alive to cache page optimization projects
主成分计算权重
ArrayList扩容详解
Can hero sports go public against the wind?
Data warehouse (3) star model and dimension modeling of data warehouse modeling
[PHP foundation] realize the connection between PHP and SQL database
EasyCVR设备录像出现无法播放现象的问题修复
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
How to retrieve the password for opening Excel files
The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
Work and leisure suggestions of old programmers
SCP -i private key usage