62,620
社区成员
发帖
与我相关
我的任务
分享public class TestSycronized implements Runnable{
int b = 100;
public synchronized void m1() throws Exception{
b =1000;
Thread.sleep(5000);
System.out.println("b ="+b);
}
public void m2(){
System.out.println(b);
}
public synchronized void run(){
try{
m1();
}catch (Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception{
TestSycronized ts= new TestSycronized();
Thread t =new Thread(ts) ;
t.start();
Thread.sleep(1000);
ts.m2();
}
}