File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
src/main/java/com/cpucode/java/condition Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 139139## [ Condition] ( src/main/java/com/cpucode/java/condition )
140140
141141- [x] [ Condition] ( src/main/java/com/cpucode/java/condition/ConditionDemo.java )
142+ - [x] [ CountDownLatch同步工具类] ( src/main/java/com/cpucode/java/condition/CountDownLatchDemo.java )
142143
143144- [ 返回文件目录] ( #文件目录 )
144145
Original file line number Diff line number Diff line change 1+ package com .cpucode .java .condition ;
2+
3+ import java .util .concurrent .CountDownLatch ;
4+
5+ /**
6+ * @author : cpucode
7+ * @date : 2021/7/30
8+ * @time : 15:59
9+ * @github : https://github.com/CPU-Code
10+ * @csdn : https://blog.csdn.net/qq_44226094
11+ */
12+ public class CountDownLatchDemo extends Thread {
13+ public static void main (String [] args ) throws InterruptedException {
14+ CountDownLatch countDownLatch = new CountDownLatch (3 );
15+
16+ new Thread (()-> {
17+ System .out .println ("" + Thread .currentThread ().getName () + "-执行中" );
18+ countDownLatch .countDown ();
19+
20+ System .out .println ("" +Thread .currentThread ().getName ()+"-执行完毕" );
21+ },"t1" ).start ();
22+
23+ new Thread (()->{
24+ System .out .println ("" +Thread .currentThread ().getName ()+"-执行中" );
25+ countDownLatch .countDown ();
26+ System .out .println ("" +Thread .currentThread ().getName ()+"-执行完毕" );
27+ },"t2" ).start ();
28+
29+ new Thread (()->{
30+ System .out .println ("" +Thread .currentThread ().getName ()+"-执行中" );
31+ countDownLatch .countDown ();
32+ System .out .println ("" +Thread .currentThread ().getName ()+"-执行完毕" );
33+ },"t3" ).start ();
34+
35+ countDownLatch .await ();
36+ System .out .println ("所有线程执行完毕" );
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments