This is probably best explained by comparing the effects that
On the other hand,
- The thread acquires the lock on the monitor for object (assuming the monitor is unlocked, otherwise the thread waits until the monitor is unlocked).1this
- The thread memory flushes all its variables, i.e. it has all of its variables effectively read from “main” memory (JVMs can use dirty sets to optimize this so that only “dirty” variables are flushed, but conceptually this is the same. See section 17.9 of the Java language specification).
- The code block is executed (in this case setting the return value to the current value of , which may have just been reset from “main” memory).1i3
- (Any changes to variables would normally now be written out to “main” memory, but for we have no changes.)1geti3()
- The thread releases the lock on the monitor for object .1this