java - 关于ConcurrentHashMap,下面是什么意思?

标签 java map concurrency

直接来自 ConcurrentHashMap javadocs :

The allowed concurrency among update operations is guided by the optional concurrencyLevel constructor argument (default 16), which is used as a hint for internal sizing. The table is internally partitioned to try to permit the indicated number of concurrent updates without contention. Because placement in hash tables is essentially random, the actual concurrency will vary.

当他们说“这被用作内部调整大小的提示”时,我不明白这一点。大小不应该由容量决定,而不是由并发级别决定吗?

最佳答案

该表是内部分区的 - 这意味着他们将表划分为 ConcurrencyLevel 分区,希望他们可以在没有任何冲突的情况下进行那么多并发更新。

但是不能保证散列数据会很好地落在这些分区中。

关于java - 关于ConcurrentHashMap,下面是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17703264/

相关文章:

java - 并发 HashMap : what's the point in locking updates only?

java - 如果我们想允许使用 putIFAbsent 覆盖 concuurentHashMap 中的值怎么办?

python - 测量 python 多处理中浪费的时间

java - 如何在 java 中使用 .readLine() 跟踪文件的读取?

java - 方法以离线方式打印数组元素,并且连字符乱序

支持 WMS 的 WPF map 控件

c++ - 将 C++ 映射复制到键和值 vector 中

java - 为什么我们不应该对单个方法使用静态和抽象?

java - 将 Javascript 数组转换为 Java 数组

ios - 如何在 iPhone 中使用图像和标签在 Mapview 中添加注释?