简体   繁体   English

ConcurrentNavigableMap,解释弱一致的迭代器

[英]ConcurrentNavigableMap, interpretation of weakly consistent iterators

In the JavaDoc for ConcurrentNavigableMap , I'm a bit confused as to the following: ConcurrentNavigableMapJavaDoc中 ,我对以下内容感到有点困惑:

The view's iterator is a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction. 视图的迭代器是一个“弱一致”的迭代器,它永远不会抛出ConcurrentModificationException,并保证遍历构造迭代器时存在的元素,并且可能(但不保证)反映构造之后的任何修改。

The wording seems the same in implementations of the interface like ConcurrentSkipListMap. 在ConcurrentSkipListMap等接口的实现中,措辞似乎相同。

What does this mean, it seems a contradiction - either it could guarantee to traverse elements as they existed upon construction, OR it might reflect modifications subsequent to construction?? 这意味着什么,它似乎是一个矛盾 - 要么它可以保证遍历构造时存在的元素,要么它可能反映了构造后的修改?

UPDATE: I'd basically like to know if creating an iterator on ConcurrentNavigableMaps like ConcurrentSkipListMap, creates a "snapshot" view of the map. 更新:我基本上想知道是否在ConcurrentNavigableMaps上创建一个像ConcurrentSkipListMap的迭代器,创建一个地图的“快照”视图。

To answer my own question, there is a discussion of the strength of the consistency guarantee provided by iterators on the concurrency-interest mailing list here . 要回答我的问题,有一个由迭代器并发利益邮件列表上提供的一致性保证强度的讨论在这里

The author of ConcurrentHashMap and ConcurrentSkipListMap, Doug Lea, appears to agree that the guarantee is not much of a guarantee at all, and that in the case of ConcurrentHashMap, the iterator can report the map to be in a state that it was never actually in. ConcurrentHashMap和ConcurrentSkipListMap的作者Doug Lea 似乎同意保证完全没有保证,并且在ConcurrentHashMap的情况下,迭代器可以报告映射处于从未实际存在的状态。 。

For those curious, the source of ConcurrentSkipListMap, specifically its internal Iter (iterator) class is here . 对于那些好奇的人来说,ConcurrentSkipListMap的来源,特别是它的内部Iter(迭代器)类就在这里

The iterator in ConcurrentSkipListMap iterates the regular nodes within the skip list, and those nodes are linked using volatile references. ConcurrentSkipListMap中的迭代器迭代跳过列表中的常规节点,并使用易失性引用链接这些节点。 It might be the case that this somewhat confusing JavaDoc statement is actually [simply] referring to a happens-before guarantee. 可能是这种有点令人困惑的JavaDoc语句实际上[简单地]指的是先发生的保证。 ie that changes made by other threads prior to creating the iterator, will be simply be visible to the thread driving the iteration. 即,在创建迭代器之前由其他线程进行的更改将仅对驱动迭代的线程可见。

The wording is strange, but actually it means that iterator may reflect some of the changes made after construction of the iterator, but it's not guaranteed to reflect all of them. 措辞很奇怪,但实际上它意味着迭代器可能反映了构造迭代器后所做的一些更改,但并不能保证反映所有这些更改。 Except for these reflected changes, elements are traversed as they existed upon construction. 除了这些反映的变化之外,元素在构造时存在。

In practice it means (roughly) that as weakly consistent iterator traverses a collection, it cannot reflect changes in parts of collection that already have been traversed, but reflects changes in parts of collection that haven't been traversed yet. 在实践中,它(大致)表示由于弱一致的迭代器遍历集合,它不能反映已经遍历的集合部分的变化,而是反映尚未遍历的集合部分的变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 失败的安全迭代器和弱一致的迭代器 - fail safe iterators and weakly consistent iterators ConcurrentSkipListSet 如何具有弱一致性的迭代器? 理解“弱一致性”的含义 - How does ConcurrentSkipListSet has Iterators that are weakly consistent? Understanding meaning of 'weakly consistent' ConcurrentHashMap的弱一致性迭代器 - Weakly consistent iterator by ConcurrentHashMap 弱一致性ConcurrentSkipListSet的含义 - Implications of weakly consistent ConcurrentSkipListSet java中的迭代器类型(弱一致) - Iterator type in java (weakly consistent) ConcurrentHashMap返回一个弱一致的迭代器,为什么我们应该使用它呢? - ConcurrentHashMap returns a weakly consistent iterator, why should we use it anyhow? 弱一致性迭代器在对hasNext方法的响应为true之后是否可以引发NoSuchElementException? - Can a weakly consistent iterator throw NoSuchElementException after it has responded true to hasNext method? 为什么将ConcurrentNavigableMap实现为跳过列表? - Why is ConcurrentNavigableMap implemented as a skip list? 如何将Java ConcurrentNavigableMap与比较器而不是TreeMap一起使用? - How can I use a Java ConcurrentNavigableMap with comparator instead of a TreeMap? 如何使用自定义比较器从排序的 ConcurrentNavigableMap 中删除元素 - How to remove an element from sorted ConcurrentNavigableMap with custom Comparator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM