Java memory model - what exactly is flushed to memory on crossing memory barrier? Java memory model - what exactly is flushed to memory on crossing memory barrier? multithreading multithreading

Java memory model - what exactly is flushed to memory on crossing memory barrier?


When a memory barrier is crossed JVM synchronizes all locally (in context of the current thread) cached variables with the main memory. Besides that, it removes any locally cached data that is marked as dirty in the main memory.

Regarding the volatile - yes, it also synchronizes everything locally cached with the main memory, not only the single volatile field (since 1.5)

http://www.javamex.com/tutorials/synchronization_volatile_java_5.shtml