62,620
社区成员
发帖
与我相关
我的任务
分享
public class TestThread implements Runnable {
int b = 10;
public synchronized void m1() throws Exception {
b = 3000;
Thread.sleep(2000);
System.out.println(Thread.currentThread().getName() + " b=" + b);
}
// public synchronized void m2() throws Exception{
public void m2() throws Exception {
b = 2000; // 是这。将它标记为(一)
Thread.sleep(1000);
//b = 2000; //就是这。将它标记为(二)
}
public void run() {
try {
m1();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
TestThread TI = new TestThread();
Thread t = new Thread(TI);
t.start();
for( int i = 0; i <10000; i++ )
;
TI.m2();
System.out.println(Thread.currentThread().getName() + " b=" + TI.b);
}
}