July 2018
Intermediate to advanced
266 pages
7h 11m
English
In order to force changes in a variable to be immediately visible to other threads, we can use the annotation @Volatile, a in the following example:
@Volatilevar shutdownRequested = false
This will guarantee visibility of changes for other threads as soon as the value is changed. This means that if thread X modifies the value of shutdownRequested, thread Y will be able to see the change immediately.
Read now
Unlock full access