April 2017
Intermediate to advanced
594 pages
25h 15m
English
The volatile keyword only works well when the value of the shared variable is only modified by one thread. If the variable is modified by multiple threads, the volatile keyword doesn't protect you from possible data-race conditions. It also doesn't make operations, such as + or -, atomic. For example, the ++ operator over a volatile variable is not thread-safe.
Since Java 5, Java Memory Model has a happens--before guarantee established with the volatile keyword. This fact has two implications:
Read now
Unlock full access