lock锁的问题求解--->半天了 没看懂
public class Test15 {private int num = 0;
public Test15(int num){
this.num=num;
}
private Lock lock4Add = new ReentrantLock();
public void add(){
for (int i = 0; i < 10000; i++) {
lock4Add.lock();
num=num+1;
lock4Add.unlock();
try {
Thread.sleep((long)0.7);
} catch (InterruptedException e){
e.printStackTrace();
}
}
System.out.println(num);
}
}
上面红色的3段代码不是很懂 lock 0的时候是开 1的时候是关 为毛num=1了 它就打开
本来等于0 确是关闭呢???????