3.1.5 倒计时器:CountDownLatch

package 第三章.倒计时器CountDownLatch;

import java.util.concurrent.CountDownLatch;

/**
* Created by zzq on 2018/1/24.
*/
public class CountDoenLatchTest implements Runnable{
static CountDownLatch countDownLatch=new CountDownLatch(3);
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
countDownLatch.countDown();
}

public static void main(String[] args) throws InterruptedException {
CountDoenLatchTest countDoenLatchTest=new CountDoenLatchTest();
Thread thread=new Thread(countDoenLatchTest);
Thread thread2=new Thread(countDoenLatchTest);
Thread thread3=new Thread(countDoenLatchTest);
thread.start();
// thread2.start();
// thread3.start();
countDownLatch.await();
System.out.println("主线程执行----------");
}
}
posted @ 2018-02-07 10:46  anxbb  阅读(140)  评论(0编辑  收藏  举报