这是代码:
public class ThreadCacheSample {
int a = 1;
int b = 2;
public void change() {
a = 3;
b = a;
}
public void print() {
if (a == 1 && b == 3) {
// why this is happening?
System.out.println("Thread[" + Thread.currentThread().getName() + "]Confused1 : a = 1, b = 3");
} else if (a == 3 && b == 2) {
// why this is happening, too?
System.out.println("Thread[" + Thread.currentThread().getName() + "]Confused2 : a = 3, …Run Code Online (Sandbox Code Playgroud)