日期:2014-05-20 浏览次数:20834 次
public class ad13 implements Runnable
{
int b = 100;
public static void main(String[] args) throws Exception{
ad13 a = new ad13();
Thread t = new Thread(a);
t.start();
Thread.sleep(1000);
a.m2();
}
public synchronized void m1()
{
this.b = 2000;
try
{
Thread.sleep(5000);
System.out.println("b = " + b);
} catch(InterruptedException e){
e.printStackTrace();
}
}
public void m2()
{
this.b = 1000;
}
public void run()
{
m1();
}
}
public synchoronized void m2()
{
this.b = 1000;
}