一个程序问题。关于synchornized的
public class TT implements Runnable {
int b = 100;
public synchronized void m1() throws Exception{
//Thread.sleep(2000);
b = 1000;
Thread.sleep(5000);
//System.out.println("b = " + b);
}
public synchronized void m2() throws Exception {
Thread.sleep(6000);
b = 2000;
//System.out.println("b = " + b);
}
public void run() {
try {
m1();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
TT tt = new TT();
Thread t = new Thread(tt);
t.start();
tt.m2();
System.out.println(tt.b);
}
}
为什么执行结果是1000,不应该m2是休眠6s,比m1要长,他应该是最后修改数据的,应该是2000啊!哪位大侠帮忙一下啊!