Java多线程系列--“JUC集合”06之 ConcurrentSkipListSet

论坛 期权论坛     
选择匿名的用户   2021-6-2 17:28   900   0
<div class="blogpost-body" id="cnblogs_post_body">
<h3><strong><span style="font-family:&#39;黑体&#39;;font-size:18pt;line-height:1.5;">概要</span></strong></h3>
<p><span style="font-size:14px;">本章对Java.util.concurrent包中的ConcurrentSkipListSet类进行详细的介绍。内容包括:<br><a href="http://www.cnblogs.com/skywang12345/p/3498634.html#p1"><span style="font-size:14px;">ConcurrentSkipListSet介绍<br></span></a><a href="http://www.cnblogs.com/skywang12345/p/3498634.html#a22">ConcurrentSkipListSet原理和数据结构</a><br><a href="http://www.cnblogs.com/skywang12345/p/3498634.html#p2"><span style="font-size:14px;">ConcurrentSkipListSet函数列表</span></a><br><a href="http://www.cnblogs.com/skywang12345/p/3498634.html#a4"><span style="font-size:14px;">ConcurrentSkipListSet源码(JDK1.7.0_40版本)</span></a><br><a href="http://www.cnblogs.com/skywang12345/p/3498634.html#a5"><span style="font-size:14px;">ConcurrentSkipListSet示例</span></a></span></p>
<p><span style="font-size:14px;">转载请注明出处:<a href="http://www.cnblogs.com/skywang12345/p/3498634.html">http://www.cnblogs.com/skywang12345/p/3498634.html</a></span></p>
<p> </p>
<h3><span style="font-family:&#39;黑体&#39;;font-size:18pt;line-height:1.5;"><strong><a name="p1"></a>ConcurrentSkipListSet介绍</strong></span></h3>
<p><span style="font-size:14px;">ConcurrentSkipListSet是线程安全的有序的集合,适用于高并发的场景。<br><span style="font-size:14px;">ConcurrentSkipListSet和<a href="http://www.cnblogs.com/skywang12345/p/3311268.html">TreeSet</a>,它们虽然都是有序的集合。但是,第一,它们的线程安全机制不同,TreeSet是非线程安全的,而ConcurrentSkipListSet是线程安全的。第二,ConcurrentSkipListSet是通过<a href="http://www.cnblogs.com/skywang12345/p/3498556.html">ConcurrentSkipListMap</a>实现的,而TreeSet是通过TreeMap实现的。</span></span></p>
<p> </p>
<h3><strong><span style="font-family:&#39;黑体&#39;;font-size:18pt;line-height:1.5;"><a name="a22"></a>ConcurrentSkipListSet原理和数据结构</span></strong></h3>
<p><span style="font-size:14px;">ConcurrentSkipListSet的数据结构,如下图所示:</span></p>
<p><span style="font-size:14px;"><a href="https://images0.cnblogs.com/blog/497634/201312/30231618-c5642dcd06d344269bfda4f05f431951.jpg"><img alt="" height="274" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-ea66707d5365e80fefdc6039ba99bbed.jpg" width="400"></a></span></p>
<p><span style="font-size:14px;"><strong>说明</strong>:<br><span style="font-size:14px;">(01) ConcurrentSkipListSet继承于AbstractSet。因此,它本质上是一个集合。<br><span style="font-size:14px;">(02) ConcurrentSkipListSet实现了NavigableSet接口。因此,ConcurrentSkipListSet是一个有序的集合。<br><span style="font-size:14px;">(03) ConcurrentSkipListSet是通过ConcurrentSkipListMap实现的。它包含一个 ConcurrentNavigableMap对象m,而m对象实际上是ConcurrentNavigableMap的实现类 ConcurrentSkipListMap的实例。ConcurrentSkipListMap中的元素是key-value键值对;而 ConcurrentSkipListSet是集合,它只用到了ConcurrentSkipListMap中的key!</span></span></span></span></p>
<p> </p>
<h3><span style="font-family:&#39;黑体&#39;;font-size:18pt;line-height:1.5;"><strong><a name="p2"></a>ConcurrentSkipListSet函数列表</strong></span></h3>
<div class="cnblogs_code">
  <div class="cnblogs_code_toolbar">
   <span class="cnblogs_code_copy"><a title="复制代码"><img alt="复制代码" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-48304ba5e6f9fe08f3fa1abda7d326ab.gif"></a></span>
  </div>
  <pre class="blockcode"><span style="color:#008000;">//<span style="color:#008000;"> 构造一个新的空 set,该 set 按照元素的自然顺序对其进行排序。
<span style="color:#000000;">ConcurrentSkipListSet()
<span style="color:#008000;">//<span style="color:#008000;"> 构造一个包含指定 collection 中元素的新 set,这个新 set 按照元素的自然顺序对其进行排序。
ConcurrentSkipListSet(Collection&lt;? <span style="color:#0000ff;">extends E&gt;<span style="color:#000000;"> c) <span style="color:#008000;">//<span style="color:#008000;"> 构造一个新的空 set,该 set 按照指定的比较器对其元素进行排序。 ConcurrentSkipListSet(Comparator&lt;? <span style="color:#0000ff;">super E&gt;<span style="color:#000000;"> comparator) <span style="color:#008000;">//<span style="color:#008000;"> 构造一个新 set,该 set 所包含的元素与指定的有序 set 包含的元素相同,使用的顺序也相同。 ConcurrentSkipListSet(SortedSet&lt;E&gt;<span style="color:#000000;"> s) <span style="color:#008000;">//<span style="color:#008000;"> 如果此 set 中不包含指定元素,则添加指定元素。 <span style="color:#0000ff;">boolean<span style="color:#000000;"> add(E e) <span style="color:#008000;">//<span style="color:#008000;"> 返回此 set 中大于等于给定元素的最小元素;如果不存在这样的元素,则返回 null。 <span style="color:#000000;">E ceiling(E e) <span style="color:#008000;">//<span style="color:#008000;"> 从此 set 中移除所有元素。 <span style="color:#0000ff;">void<span
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP