为什么ConcurrentHashMap
的默认并发级别是16,为什么不是18?
最佳答案
我刚刚检查了并发映射的实现,发现了以下内容:
/**
* The default concurrency level for this table. Unused but
* defined for compatibility with previous versions of this class.
*/
private static final int DEFAULT_CONCURRENCY_LEVEL = 16;
它似乎只是为了与旧版本兼容而定义的。
对于为什么是 16 而不是 18 的问题。我猜这是因为由于按位运算和实现中更好的内存管理,它最好是 2 的幂。
关于java - ConcurrentHashMap默认并发级别的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50227582/