public class Test implements Runnable{
public String msg = "show"
public synchronized void show() {
while (true) {
System.out.println(msg);
}
}
public void print() {
while (true) {
System.out.println("print");
}
}
public void run() {
show();
}
public static void main(String[] args) {
Test test = new Test();
Thread t = new Thread(test);
t.start();
//test.msg = "other"; //1
}
}
看似同步的危险代码