有人知道是怎么回事吗
代码:
public static void main(String[] args) {
threadConflict();
}
private static int i = 1000000;
private static void threadConflict() {
Runnable r = () -> {
while (--i >= 0) {
if (i <= 3) {
System.out.println(Thread.currentThread().getName() + ", " + i);
}
}
};
Thread[] ts = new Thread[3];
for (int j = 0; j < ts.length; j++) {
ts[j] = new Thread(r);
ts[j].start();
}
}
结果:
这个13w是怎么来的 咋就进到输出语句了?
代码:
public static void main(String[] args) {
threadConflict();
}
private static int i = 1000000;
private static void threadConflict() {
Runnable r = () -> {
while (--i >= 0) {
if (i <= 3) {
System.out.println(Thread.currentThread().getName() + ", " + i);
}
}
};
Thread[] ts = new Thread[3];
for (int j = 0; j < ts.length; j++) {
ts[j] = new Thread(r);
ts[j].start();
}
}
结果:
这个13w是怎么来的 咋就进到输出语句了?