在try
块下面,必须按该顺序执行 3 条语句。语句是否有可能出现乱序?JVM 是否在 juc 类中向前看以查看同步指标(同步的、易失的)并确定它不能重新排序执行?
private Deque<Integer> deque = new LinkedList<Integer>();
private Lock lock = new ReentrantLock();
private Condition condition = lock.newCondition();
class Producer implements Runnable {
@Override
public void run() {
while (true) {
try {
lock.lock();
deque.add(1);
condition.signalAll();
} finally {
lock.unlock();
}
}
}
}