package com.study;
import java.util.concurrent.CountDownLatch;
public class ThreadUnsafe {
private static int num =0;
private static void inc(){
for(int i=0;i<100;i++){
num++;
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private static CountDownLatch countDownLatch = new CountDownLatch(10);
public static void main(String[] args) {
for(int i=0;i<100;i++){
new Thread(
new Runnable() {
public void run() {
inc();
countDownLatch.countDown();
}
}
).start();
}
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(num);
}
}