JCIP @GuardedBy在[Java理论与实践:管理波动率]文章代码中的警告

时间:2017-01-30 06:07:36

标签: java intellij-idea

我尝试按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++;
    }
}

但是,我收到了警告

enter image description here

有人可以解释发生了什么吗?代码不正确吗?

0 个答案:

没有答案