/**
* @create on 17/3/27
* @description
*/
public class Main {
static volatile int i = 0;
public static class PlusTask implements Runnable{
@Override
public void run(){
for(int k=0; k<10000; k++)
i++;
}
}
public static void main(String[] args) throws InterruptedException{
Thread[] threads = new Thread[10];
for(int i=0;i<10;i++){
threads[i] = new Thread(new PlusTask());
threads[i].start();
}
for(int i=0;i<10;i++){
threads[i].join();
}
System.out.println(i);
}
}
請教各位大牛 為什么這里的輸出總是小于10000? 已經調用了thread.join
添加回答
舉報
0/150
提交
取消