当前位置:网站首页>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 */
}
边栏推荐
- Fix the black screen caused by iPhone system failure
- [CF559E]Gerald and Path
- PTA year of birth
- The ultimate version of the 13th simulation of the single chip microcomputer provincial competition of the Blue Bridge Cup
- Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
- Is online stock account opening safe? Is it reliable?
- Rust language - cargo, crates io
- Set the style of QT property sheet control
- LeetCode 148. Sort linked list
- Slider verification code identification gadget display
猜你喜欢

MySQL connection tools

Blue Bridge Cup real topic: the shortest circuit

Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)

Penetration practice vulnhub range Keyring

An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press

Yuancosmos game farmersworld farmers world - core content of the second conference in China!

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

540. Single element in ordered array

Computer network interview assault

Yolov5 practice: teach object detection by hand
随机推荐
LeetCode 148. Sort linked list
[CF559E]Gerald and Path
Mysql database design
What impact will multinational encryption regulation bring to the market in 2022
What are the six steps of the software development process? How to draw software development flow chart?
EasyCVR设备录像出现无法播放现象的问题修复
Basic concepts of binary tree
At present, where is the most formal and safe account opening for futures speculation? How to open a futures account?
An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Length of learning and changing
Fix the problem that easycvr device video cannot be played
Mujoco's biped robot Darwin model
Explain in detail the process of realizing Chinese text classification by CNN
Gold, silver and four job hopping, interview questions are prepared, and Ali becomes the champion
Draw drawing process of UI drawing process
Software construction scheme of smart factory collaborative management and control application system
The latest intelligent factory MES management system software solution
Apk signature process introduction [easy to understand]
Apache iceberg source code analysis: schema evolution