I have a `HashMap` in my program which is accessed by multiple threads, and is occasionally set by a single thread.
Map myMap = new HashMap();
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?
Thanks to the answers, I've realized this question is actually independent of the `HashMap`. It was more a question about object reference assignment. possible duplicate of In Java, is it safe to change a reference to a HashMap read concurrently
以上就是Is setting a HashMap thread safe?的详细内容，更多请关注web前端其它相关文章！