package com.xwj.Thread;
public class TestSynchronized1 {
public static void main(String[] args){
Runner2 r2 = new Runner2();
Thread thread = new Thread(r2);
thread.start();
r2.method2();
}
}
class Runner2 implements Runnable{
int b = 0;
public void run() {
method1();
}
public synchronized void method1(){
b = 100;
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("b = "+b);
}
public void method2(){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
b = 500;
}
}
请写出运行结果: