我尝试按Java theory and practice: Managing volatility部分所述实现此类,模式#5:廉价的读写锁定技巧
@ThreadSafe
public class CheesyCounter {
// Employs the cheap read-write lock trick
// All mutative operations MUST be done with the 'this' lock held
@GuardedBy("this") private volatile int value;
public int getValue() { return value; }
public synchronized int increment() {
return value++;
}
}
但是,我收到了警告:
有人可以解释发生了什么吗?代码不正确吗?