立即学习:https://edu.csdn.net/course/play/9827/208781?utm_source=blogtoedu
import java.util.concurrent.CountDownLatch;
public class test1 {
private static int number;
public static void insert(){
number++;
}
public static void main(String[] args) {
final CountDownLatch count=new CountDownLatch(10);
for(int i=0;i<10;i++){
new Thread(new Runnable(){
public void run() {
// TODO Auto-generated method stub
for (int j = 0; j < 500; j++) {
insert();
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
count.countDown();
}
}
).start();
}
while(true){
if(count.getCount()==0){
System.out.println(number);
break;
}
}
}
}