同步块中的volatile变量是否会阻止锁定省略?

时间:2016-02-20 14:15:10

标签: java multithreading

例如,

public class Counter {
    private volatile long count;

    public long vaule() {
         //Since count is volatile and this is read only,
         // We don't need to use synchronized here 
        return count;
    }

    // This method will only be accessed from a single thread.
    public void increment() {
        synchronized (this) {
            count++;
        }
    }

}

假设上述增量只能从一个线程访问,那么由于为同步引入的锁定消除(Elision)优化,JIT编译器将优化该方法中的synchronized ?

0 个答案:

没有答案
相关问题