I have the following code:
我有以下代码:
public class Derived implements Runnable {
private int num;
public synchronized void setA(int num) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
System.out.println("Setting value " + Thread.currentThread().getName());
this.num = num;
}
@Override
public void run()
{
System.out.println("In run: " + Thread.currentThread().getName());
setA(20);
}
public static void main(String[] args) {
Derived obj = new Derived();
Thread t1 = new Thread(obj);
t1.start();
obj.setA(32);
}
}
publ