当前位置:网站首页>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 */
}
边栏推荐
- Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
- Can hero sports go public against the wind?
- Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
- 网上股票开户安全吗?是否可靠?
- Blue Bridge Cup real topic: the shortest circuit
- . Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
- Roll out! Enlightenment!
- . Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
- Blackwich: the roadmap of decarbonization is the first step to realize the equitable energy transformation in Asia
- Operation of cmake under win
猜你喜欢

C# SelfHost WebAPI (2)

Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?

What impact will multinational encryption regulation bring to the market in 2022

Computer network interview assault

Yolov5 practice: teach object detection by hand

The 13th simulation problem of the single chip microcomputer provincial competition of the Blue Bridge Cup

Database - MySQL advanced SQL statement (I)

Classpath classpath

Force buckle day33

Penetration practice vulnhub range Keyring
随机推荐
Calculation of intersection of two line segments
Nielseniq found that 60% of the re launched products had poor returns
Glidefast consulting was selected as the elite partner of servicenow in 2022
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
Mujoco XML modeling
Blue Bridge Cup real question: score statistics
Data warehouse (3) star model and dimension modeling of data warehouse modeling
Cloud computing - make learning easier
Distributed task queue: Celery usage record
Blue Bridge Cup real topic: the shortest circuit
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
MES production equipment manufacturing execution system software
What is web application security testing technology?
Apache iceberg source code analysis: schema evolution
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Small exercise -- subnet division and summary
Is Huishang futures a regular futures platform? Is it safe to open an account in Huishang futures?
Is the fund of futures account safe? How to open an account?
Slider verification code identification gadget display
MySQL connection tools