何时应用ConcurrentSkipListMap? [英] When should I use ConcurrentSkipListMap?

查看:869
本文介绍了何时应用ConcurrentSkipListMap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中, ConcurrentHashMap 有更好的多线程解决方案。那么当我应该使用 ConcurrentSkipListMap ?是否是冗余?



这两者之间的多线程方面是常见的吗?

解决方案

这两个类别有所不同。



ConcurrentHashMap 不保证其作为合同一部分的运行时间。它还允许调整某些负载因子(大致上,线程数量同时修改它)。



ConcurrentSkipListMap保证了各种各样的平均O(log(n))性能操作。它也不支持并发调优。 ConcurrentSkipListMap 还有一些操作, ConcurrentHashMap 不:ceilingEntry / Key,floorEntry / Key等还维护一个排序顺序,否则如果您使用 ConcurrentHashMap ,则必须计算(显着费用)。



基本上,为不同的用例提供了不同的实现。如果您需要快速单键/值对加法和快速单键查找,请使用 HashMap 。如果您需要更快的顺序遍历,并且可以承受额外的插入费用,请使用 SkipListMap



虽然我希望实现与O(1)插入/查找的一般哈希映射保证大致一致;忽略重新哈希


In Java, ConcurrentHashMap is there for better multithreading solution. Then when should I use ConcurrentSkipListMap? Is it a redundancy?

Does multithreading aspects between these two are common?

解决方案

These two classes vary in a few ways.

ConcurrentHashMap does not guarantee* the runtime of its operations as part of its contract. It also allows tuning for certain load factors (roughly, the number of threads concurrently modifying it).

ConcurrentSkipListMap, on the other hand, guarantees average O(log(n)) performance on a wide variety of operations. It also does not support tuning for concurrency's sake. ConcurrentSkipListMap also has a number of operations that ConcurrentHashMap doesn't: ceilingEntry/Key, floorEntry/Key, etc. It also maintains a sort order, which would otherwise have to be calculated (at notable expense) if you were using a ConcurrentHashMap.

Basically, different implementations are provided for different use cases. If you need quick single key/value pair addition and quick single key lookup, use the HashMap. If you need faster in-order traversal, and can afford the extra cost for insertion, use the SkipListMap.

*Though I expect the implementation is roughly in line with the general hash-map guarantees of O(1) insertion/lookup; ignoring re-hashing

这篇关于何时应用ConcurrentSkipListMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆