-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestCountDown.java
More file actions
27 lines (25 loc) · 835 Bytes
/
TestCountDown.java
File metadata and controls
27 lines (25 loc) · 835 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
package MultiThread;
import java.util.concurrent.CountDownLatch;
public class TestCountDown {
public static void main(String[] args) {
System.out.println("main thread start");
final CountDownLatch latch = new CountDownLatch(3);
for (int i = 0; i < 3; i++) {
new Thread(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("sleep exception");
}
System.out.println(" i'm " + latch.getCount() + "thread");
latch.countDown();
}).start();
}
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("main thread end");
}
}