当前位置:网站首页>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 */
}
边栏推荐
- Oracle TRUNC function processing date format
- Detailed explanation of ArrayList expansion
- Force buckle day33
- [PHP foundation] realize the connection between PHP and SQL database
- C operator overloads the query table
- February 16, 2022 Daily: graph neural network self training method under distribution and migration
- The method of real-time tracking the current price of London Silver
- What are the six steps of the software development process? How to draw software development flow chart?
- Financial judgment questions
- MES production equipment manufacturing execution system software
猜你喜欢
![[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out](/img/f3/20b73f3545cdd17b9fbc52bf493ab4.jpg)
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out

Search 2D matrix 2

transform. Forward and vector3 Differences in the use of forward

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

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

Mujoco model learning record

The method of real-time tracking the current price of London Silver

必看,时间序列分析

Apache iceberg source code analysis: schema evolution

Rotation order and universal lock of unity panel
随机推荐
Opencv map reading test -- error resolution
Domestic spot silver should be understood
When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
What are the legal risks of NFT brought by stars such as curry and O'Neill?
SCP -i private key usage
Mysql database design
PMP daily three questions (February 15, 2022)
Cassette helicopter and alternating electric field magnetic manometer DPC
Yolov5 practice: teach object detection by hand
The latest software scheme of the intelligent information management system of the armed police force
Terms related to K line
The method of real-time tracking the current price of London Silver
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
網上股票開戶安全嗎?是否可靠?
Batch export all pictures in PPT in one second
Extract the compressed package file and retrieve the password
Apache iceberg source code analysis: schema evolution
How to retrieve the password for opening Excel files
What impact will multinational encryption regulation bring to the market in 2022
Depth first search - DFS (burst search)