packagecom.zzf.concurrence.cdtest;
importjava.util.concurrent.CountDownLatch;
publicclassCountdownLatchTest {
privatestaticCountDownLatchcd=newCountDownLatch(1000);
private static final int CONCURRENCE_COUNT = 1000 + 1;
publicstaticvoidmain(String[]args) {
// 一千个线程,同时怼一个方法
for(inti= 0;i
newThread(newSendTask()).start();
cd.countDown();
}
longcurrentTimeMillis= System.currentTimeMillis();
try{
cd.countDown();
cd.await();
}catch(InterruptedExceptione) {
//TODOAuto-generated catch block
e.printStackTrace();
}
System.out.println("当前用时:"+ (System.currentTimeMillis() -currentTimeMillis));
}
private static class SendTask implements Runnable {
@Override
publicvoidrun() {
try{
cd.await();
}catch(InterruptedExceptione) {
e.printStackTrace();
}
sendsms();
}
}
private static void sendsms() {
// System.out.println("信息发送成功"+System.currentTimeMillis());
}
}
网友评论