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

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

问题描述

我刚刚在Java 6 API中看到了这个数据结构,我很好奇当它是一个有用的资源。我正在考取scjp考试,我没有看到它涵盖了凯西·塞拉的书,即使我已经看到模拟考试问题提到它。

解决方案

ConcurrentSkipListSet ConcurrentSkipListMap 在需要多个线程访问的排序容器时很有用。这些实质上是TreeMap和TreeSet的并发代码的等价物。



JDK 6的实现基于高性能动态无锁哈希表和基于列表的集由迈克尔·迈克尔在IBM,这表明您可以实现大量使用比较和交换(CAS)操作的跳过列表上的操作。这些是无锁的,所以你不用担心使用这些类时 synchronized (对于大多数操作)的开销。



目前没有红黑树基于并发的Map /在Java中设置实现。我看过文献,发现了一个情侣 论文显示并发的RB树优于跳过列表,但是许多这些测试都是使用事务内存完成的,目前在任何主要架构的硬件中都不支持。



我假设JDK的人在这里跳过列表,因为实现是众所周知的,因为使其无锁是简单和便携(使用CAS)。如果有人关心澄清,请做。我很好奇。


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 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.

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.

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.

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天全站免登陆