java多线程之hashmap concurrenthashmap的状态同步

最近在高并发的系统中发现,concurrenthashmap除了大家熟知的避免循环期间发生ConcurrentModificationException异常外,还有重要的一点是Retrievals reflect the results of the most recently completed update operations holding upon their onset,也就是get的时候会得到最新后的结果,线程间亦如此。而hashmap并没有提及一点,所以并不能保证另一个线程在之后能够立刻读取到最新的值。

所以,如果希望一个线程对map所做的变更在另一个线程立刻可见,应使用concurrenthashmap。

posted @ 2016-11-09 13:21  zhjh256  阅读(372)  评论(0编辑  收藏  举报