The modifier volatilehas nothing to do with the class in question - it applies only to the variable cMap. This only affects how the thread retrieves or changes the value of this variable. By the time you typed the methods on the specified object, you were beyond the scope of bailiwick volatile.
As you say, it basically ensures that all threads are guaranteed to see value changes cMap(i.e. refer to another map).
This may be a good idea - or it may not be, depending on what the rest of the code does. If you can do this final, for example, you will not need volatile...
source
share