Is setting a HashMap thread safe?

I have a `HashMap` in my program which is accessed by multiple threads, and is occasionally set by a single thread. For example: 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? 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.
possible duplicate of In Java, is it safe to change a reference to a HashMap read concurrently

以上就是Is setting a HashMap thread safe?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准