上面是截图,菜鸟不明白问题出在哪里?请高手赐教!谢谢
下面把代码也贴出来!
public class Demo01 {
volatile static Integer i = 0;
static class ChangeThread implements Runnable {
@Override
public void run() {
increase();
}
private synchronized void increase() {
for (int ii = 0; ii < 100; ii++) {
i++;
}
}
}
public static void main(String[] args) throws InterruptedException {
Thread[] threads = new Thread[10];
for (int ii = 0; ii < 10; ii++) {
threads[ii] = new Thread(new ChangeThread());
threads[ii].start();
}
for (int ii = 0; ii < 10; ii++) {
threads[ii].join();
}
System.out.println(i);
}
}