If in a class I have a ConcurrentHashMap instance that will be modified and read by multiple threads I might define like this:
public class My Class {
p
volatile
is used for variables that their value may change, in certain cases, otherwise there is no need for volatile
, and final
means that the variable may not change, so there's no need for volatile
.
Your concurrency concerns are important, but making the HashMap
volatile will not solve the problem, for handling the concurrency issues, you already use ConcurrentHashMap
.