什么时候ConcurrentSkipListSet有用? [英] When is a ConcurrentSkipListSet useful?

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

问题描述

我刚看到这个Java 6 API的数据结构,我很好奇什么时候它是一个有用的资源。我正在研究scjp考试,我看不到它覆盖在凯西·塞拉利的书,即使我看到模拟考试的问题,提及它。

I just saw this data-structure on the Java 6 API and I'm curious about when it would be an useful resource. I'm studying for the scjp exam and I don't see it covered on Kathy Sierra's book, even though I've seen mock exam questions that mention it.

推荐答案

ConcurrentSkipListSet ConcurrentSkipListMap 在需要一个将由多个线程访问的排序容器时非常有用。这些基本上是用于并发代码的TreeMap和TreeSet的等价物。

ConcurrentSkipListSet and ConcurrentSkipListMap are useful when you need a sorted container that will be accessed by multiple threads. These are essentially the equivalents of TreeMap and TreeSet for concurrent code.

JDK 6的实现基于高性能动态无锁哈希表和基于列表的集合,使用比较和交换(CAS)对跳过列表执行大量操作操作。这些是无锁的,所以你不必担心在使用这些类时 synchronized (对于大多数操作)的开销。

The implementation for JDK 6 is based on High Performance Dynamic Lock-Free Hash Tables and List-Based Sets by Maged Michael at IBM, which shows that you can implement a lot of operations on skip lists atomically using compare and swap (CAS) operations. These are lock-free, so you don't have to worry about the overhead of synchronized (for most operations) when you use these classes.

目前没有基于红黑树的并发地图/在Java中设置实现。我仔细看了一遍文献,发现了一个情侣 论文显示并发RB树胜过跳过列表,但很多这些测试是通过事务内存

There's currently no Red-Black tree based concurrent Map/Set implementation in Java. I looked through the literature a bit and found a couple papers that showed concurrent RB trees outperforming skip lists, but a lot of these tests were done with transactional memory, which isn't supported in hardware on any major architectures at the moment.

我假设JDK的用户在这里使用了一个跳过列表,因为实现是很好的已知,因为使其无锁是简单和便携(使用CAS)。如果有人想要澄清,请做。我很好奇。

I'm assuming the JDK guys went with a skip list here because the implementation was well-known and because making it lock-free was simple and portable (using CAS). If anyone cares to clarify, please do. I'm curious.

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

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