Below in try
block, there are 3 statements must be executed in that order. Is there any possibility that statements could run out of order? Does JVM look ahead in j.u.c classes to see synchronization indicators (synchronized, volatile) and figure out it must not reorder the execution?
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();
}
}
}
}