问题汇总
1、
public class Test {
private static volatile int a = 65537;
public static void main(String[] args) {
new Thread(() -> {
while (true) {
if (a == 65538) {
a = 65537;
System.out.println("修改");
} else if (a == 65537) {
continue;
} else {
try {
throw new Exception("线程1出问题了"+a);
} catch (Exception e) {
e.printStackTrace();
break;
}
}
}
}).start();
new Thread(()->{
while (true) {
if (a == 65537) {
a = 65538;
System.out.println("修改");
} else if (a == 65538) {
continue;
} else {
try {
throw new Exception("线程2出问题了"+a);
} catch (Exception e) {
e.printStackTrace();
break;
}
}
}
}).start();
}
}最后更新于
