gpt4 book ai didi

java - 哪些操作取决于 LinkedHashMap 的容量?是否有可用的并发版本?

转载 作者:行者123 更新时间:2023-11-29 09:11:18 25 4
gpt4 key购买 nike

我使用 ConcurrentHashMap 作为我的数据结构,因为多个线程将同时读取和写入它。但我发现客户端代码也需要经常迭代它。所以我看了一下 LinkedHashMap 类,它提供了更好的迭代性能,并在它的 java 文档中找到了这个部分:

A linked hash map has two parameters that affect its performance: initial capacity and load factor. They are defined precisely as for HashMap. Note, however, that the penalty for choosing an excessively high value for initial capacity is less severe for this class than for HashMap, as iteration times for this class are unaffected by capacity.

所以迭代不依赖于容量。对于 LinkedHashMap 或一般的 HashMap,还有哪些其他操作依赖于初始容量?最近的 JDK 版本中是否有 LinkedHashMap 的任何并发版本?

最佳答案

Except for iteration what other operations depend on initial capacity for a LinkedHashMap

如前所述,容量对于迭代并不重要。初始容量几乎不会产生太大差异,如果您的负载系数合理,容量将根据需要增长。

Also is there any concurrent version of the LinkedHashMap in recent JDK versions

ConcurrentHashMap 是最接近的。如果您需要并发访问,请使用这个。

关于java - 哪些操作取决于 LinkedHashMap 的容量?是否有可用的并发版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12299731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com