public class TT extends Thread {
int b = 100;
public synchronized void m1()throws Exception{
b=1000;
Thread.sleep(3000);
System.out.println("m1:"+"b="+b);
}
public void m2(){
System.out.println("m2"+b);
}
public void run(){
try {
m1();
} catch (Exception e) {
}
}
public static void main(String[] args) throws Exception {
TT tt = new TT();
Thread t = new Thread(tt);
t.start();
Thread.sleep(100);
tt.m2();
}
}
答案是 先输出m2的1000 在输出m1的1000,这里我就不懂了,int b = 100,为什么被改变了?我以为m2应该输出还是100的呢?
|
|