package test;
import java.util.concurrent.CountDownLatch;
public class CountDownLatchDemo {
/**
*
* @author Administrator/2012-3-1/上午09:57:05
*/
public static void main(String[] args) {
int threadNumber = 10;
final CountDownLatch countDownLatch = new CountDownLatch(threadNumber);
for (int i = 0; i < threadNumber; i++) {
final int threadID = i;
new Thread() {
public void run() {
try {
Thread.sleep((long) (Math.random() * 10000));
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(String.format("threadID:[%s] finished!!", threadID));
countDownLatch.countDown();
}
}.start();
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("main thread finished!!");
}
}