日期:2014-05-20 浏览次数:21077 次
package com.syn;
public class TT implements Runnable {
int b = 100;
public static void main(String[] args) throws Exception {
TT t = new TT();
Thread t1 = new Thread(t);
t1.start();
t.m2();
Thread.sleep(6000);
System.out.println("m2" +" :" +t.b);
}
@Override
public void run() {
try {
m1();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public synchronized void m1() throws Exception {
b = 1000;
Thread.sleep(5000);
System.out.println("m1" +" :" +b);
}
public synchronized void m2() throws InterruptedException {
Thread.sleep(1000);
b = 2000;
System.out.println("m2" +" :" +b);
}
}