例如,
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 ?