What is the correct thread safe collection to map an integer and a string in Java?
Is ConcurrentHashMap the right way to go?
private volatile ConcurrentHashMap<int, bool> chm;
What is wrong with the above declaration. Eclipse says “Syntax error on token “int”, Dimensions expected after this token”
This maps an
Integerto aString. In Java, generics must use reference types (Integer, Boolean, etc.), not primitives (int, boolean, etc.)I doesn’t need to be volatile, except in the unlikely event you’ll be putting new maps into the field from more than one thread. The map itself will take care of synchronizing mutations.