62,635
社区成员




public class TT implements Runnable {
private int b = 100;
public void m1() {
synchronized (this) {
try {
Thread.sleep(3000);
b = 1000;
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("b1 = " + b);
}
}
public void m2() {
System.out.println("b2 = " + b);
}
public void run() {
this.m1();
}
public static void main (String[] args) throws Exception {
TT t = new TT();
Thread t1 = new Thread(t);
t1.start();
Thread.sleep(500);
t.m2();
}
}
public void m2() {
System.out.println("b2 = " + b);
}
public synchronized void m2() {
System.out.println("b2 = " + b);
}