3.1.5 倒計時器:CountDownLatch
阿新 • • 發佈:2018-02-07
ble dex row ack run cat stack inter exc
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("主線程執行----------");
}
}
3.1.5 倒計時器:CountDownLatch