CountDownLatch计数器,计数完毕,wait才开始执行
public class test {
java.util.concurrent.CountDownLatch countDownLatch = new java.util.concurrent.CountDownLatch(2);
public class A implements java.lang.Runnable{
java.util.concurrent.CountDownLatch countDownLatch;
int threadName;
public A(java.util.concurrent.CountDownLatch countDownLatch,int threadName){
this.countDownLatch = countDownLatch;
this.threadName = threadName;
}
public void run(){
System.out.println(this.threadName);
this.countDownLatch.countDown();
}
}
public static void main(String[] args) throws ParseException {
test a = new test();
for(int i=1;i <=3;i++){
new Thread(new test().new A(a.countDownLatch,i)).start();
}
try {
a.countDownLatch.await();
System.out.println("30");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}