62,614
社区成员
发帖
与我相关
我的任务
分享
package lang.thread.demo;
public class NewThread implements Runnable{
int b = 100;
public synchronized void m1(){
b = 1000 ;
System.out.println("m1 : " + b);
try{
Thread.sleep(500);
}catch(InterruptedException ex){
ex.printStackTrace();
}
System.out.println("b=" + b);
}
public synchronized void m2(){
try{
Thread.currentThread().sleep(9500);
}catch(InterruptedException ex){
ex.printStackTrace();
}
b = 2000 ;
System.out.println("m2:" + b);
}
public void run(){
m1();
}
public static void main(String[] args){
NewThread nt = new NewThread();
Thread thread = new Thread(nt);
thread.start();
nt.m2();
System.out.println(nt.b);
}
}
m2:2000
2000
m1 : 1000
b=1000