package com.company.bingfa;
import java.util.concurrent.CountDownLatch;
class MyThread extends Thread{
private CountDownLatch counter;
MyThread(CountDownLatch counter){
this.counter = counter;
}
@Override
public void run() {
System.out.println(getName()+"线程执行");
counter.countDown();
}
}
public class MyCountDownLatch {
public static void main(String[] args) throws InterruptedException {
CountDownLatch counter = new CountDownLatch(2);
MyThread t1 = new MyThread(counter);
MyThread t2 = new MyThread(counter);
t1.start();
t2.start();
counter.await();
System.out.println("主线程执行");
/*
Thread-1线程执行
Thread-0线程执行
主线程执行
*/
}
}