-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountDownTest.java
More file actions
45 lines (31 loc) · 1020 Bytes
/
CountDownTest.java
File metadata and controls
45 lines (31 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.chen.test;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
/**
* @author : chen weijie
* @Date: 2019-09-06 10:40
*/
public class CountDownTest {
public static void main(String[] args) {
CountDownLatch countDownLatch = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
new Thread(() -> {
synchronized (countDownLatch.getClass()){
System.out.println(UUID.randomUUID().toString());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
countDownLatch.countDown();
}
}).start();
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + "执行程序....");
}
}