I have a HashMap
in my program which is accessed by multiple threads, and is occasionally set by a single thread.
For example:
Map<String, String> myMap = new HashMap<String, String>();
This is accessed by multiple threads. Once an hour, a single thread calls:
myMap = myRefreshedVersionOfTheMap;
So my question is whether or not this is thread safe. If both maps always have the key "importantKey"
, is it possible for a reading thread to ever access the map at a time when "importantKey"
does not exist?
Edit:
Thanks to the answers, I've realized this question is actually independent of the HashMap
. It was more a question about object reference assignment.