Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
像这样的类ConcurrentHashmap不会抛出这个异常;为什么?他们在内部做了什么来避免这个异常?如何防止并发 API 中的所有类出现这种情况?
ConcurrentHashmap
并发集合实现迭代器不会抛出 ConcurentModificationException,因为这是 API 的要求,请参阅 java.util.concurrent 包 javadocs。不同的实现使用不同的技术来实现这一点,例如创建集合状态的快照。您可以查看 JDK 源代码以了解实现细节。