当前位置: 首页 > news >正文

郑州网站建设流程网络策划方案

郑州网站建设流程,网络策划方案,烟台网站建设方案,河南省建设局网站首页ConcurrentLinkedQueue的源码解析(基于JDK1.8) ConcurrentLinkedQueue是Java集合框架中的一种线程安全的队列,它是通过CAS(Compare and Swap)算法实现的并发队列。在并发场景下,ConcurrentLinkedQueue能够…

ConcurrentLinkedQueue的源码解析(基于JDK1.8)

ConcurrentLinkedQueue是Java集合框架中的一种线程安全的队列,它是通过CAS(Compare and Swap)算法实现的并发队列。在并发场景下,ConcurrentLinkedQueue能够保证队列的线程安全性,同时性能也很不错。

数据结构

ConcurrentLinkedQueue是基于链表实现的队列,内部维护一个head节点和tail节点,head和tail都是指向链表中的节点。

入队操作

ConcurrentLinkedQueue的入队操作通过CAS算法实现,它的核心代码如下:

public boolean offer(E e) {checkNotNull(e);final Node<E> newNode = new Node<E>(e);for (Node<E> t = tail, p = t;;) {Node<E> q = p.next;if (q == null) {// p is last nodeif (p.casNext(null, newNode)) {// Successful CAS is the linearization point// for e to become an element of this queue,// and for newNode to become "live".if (p != t) // hop two nodes at a timecasTail(t, newNode);  // Failure is OK.return true;}// Lost CAS race to another thread; re-read next}else if (p == q)// We have fallen off list.  If tail is unchanged, it// will also be off-list, in which case we need to// jump to head, from which all live nodes are always// reachable.  Else the new tail is a better bet.p = (t != (t = tail)) ? t : head;else// Check for tail updates after two hops.p = (p != t && t != (t = tail)) ? t : q;}
}

它的流程如下:

  1. 首先,创建一个新节点newNode。
  2. 获取tail节点和tail节点的下一个节点p。
  3. 如果p为空,则说明当前节点p是队列中的最后一个节点,这时候尝试通过CAS将新节点newNode插入到链表中。
  4. 如果CAS操作成功,则表示插入成功,并且将tail指针指向新的节点newNode。
  5. 如果CAS操作失败,则说明有其他线程已经修改了tail指针,需要重新获取tail指针。
  6. 如果p不为空,则需要判断p和tail是否指向同一个节点,如果是,则说明tail指针已经落后了,需要重新获取tail指针。
  7. 如果p和tail不是同一个节点,则需要将p指向p的下一个节点。
  8. 重复上述过程,直到插入成功为止。

出队操作

ConcurrentLinkedQueue的出队操作也是通过CAS算法实现,它的核心代码如下:

public E poll() {restartFromHead:for (;;) {for (Node<E> h = head, p = h, q;;) {E item = p.item;if (item != null && p.casItem(item, null)) {// Successful CAS is the linearization point// for item to be removed from this queue.if (p != h) // hop two nodes at a timeupdateHead(h, ((q = p.next) != null) ? q : p);return item;}else if ((q = p.next) == null) {updateHead(h, p);return null;}else if (p == q)continue restartFromHead;elsep = q;}}
}

它的流程如下:

  1. 首先,获取head节点和head节点的下一个节点p。
  2. 如果p为空,则说明队列为空,直接返回null。
  3. 如果p不为空,则尝试通过CAS将p节点的元素item设置为null。
  4. 如果CAS操作成功,则表示当前节点p被成功出队,并且返回出队的元素item。
  5. 如果CAS操作失败,则说明有其他线程已经修改了当前节点p的元素item,需要重新获取head节点。
  6. 如果p的下一个节点q为空,则需要更新head节点为p,并返回null。
  7. 如果p和p的下一个节点q是同一个节点,则说明head节点已经落后了,需要重新获取head节点。
  8. 如果p和p的下一个节点q不是同一个节点,则将p指向q。
  9. 重复上述过程,直到出队成功为止。

总结

ConcurrentLinkedQueue是一种高效的并发队列,它通过CAS算法实现了线程安全的入队和出队操作。在并发场景下,ConcurrentLinkedQueue能够保证队列的线程安全性,同时性能也很不错。因此,在Java并发编程中,ConcurrentLinkedQueue是一种常用的数据结构。


文章转载自:
http://offendedly.c7629.cn
http://belgique.c7629.cn
http://unemployed.c7629.cn
http://kinematically.c7629.cn
http://chainage.c7629.cn
http://beemistress.c7629.cn
http://jewelly.c7629.cn
http://argenteous.c7629.cn
http://gilgai.c7629.cn
http://geckotian.c7629.cn
http://reaumur.c7629.cn
http://ballast.c7629.cn
http://biosystematics.c7629.cn
http://dedifferentiate.c7629.cn
http://demivolt.c7629.cn
http://nizamate.c7629.cn
http://ungreeted.c7629.cn
http://chest.c7629.cn
http://unswore.c7629.cn
http://transcutaneous.c7629.cn
http://cinnamon.c7629.cn
http://factionist.c7629.cn
http://notice.c7629.cn
http://cottage.c7629.cn
http://tomboy.c7629.cn
http://solfeggio.c7629.cn
http://backlot.c7629.cn
http://phonemicize.c7629.cn
http://reminiscence.c7629.cn
http://telodendron.c7629.cn
http://adiantum.c7629.cn
http://upright.c7629.cn
http://autohypnosis.c7629.cn
http://landmine.c7629.cn
http://fireballing.c7629.cn
http://luminary.c7629.cn
http://horsetail.c7629.cn
http://aircraftman.c7629.cn
http://somnambular.c7629.cn
http://denny.c7629.cn
http://seismography.c7629.cn
http://naturism.c7629.cn
http://chalkware.c7629.cn
http://tussive.c7629.cn
http://redevelopment.c7629.cn
http://trypsinize.c7629.cn
http://subirrigate.c7629.cn
http://scratchboard.c7629.cn
http://fibrogenesis.c7629.cn
http://bolometer.c7629.cn
http://levi.c7629.cn
http://beachy.c7629.cn
http://draughty.c7629.cn
http://wellspring.c7629.cn
http://minimill.c7629.cn
http://peduncle.c7629.cn
http://agin.c7629.cn
http://chunder.c7629.cn
http://homogenate.c7629.cn
http://amarelle.c7629.cn
http://coequal.c7629.cn
http://fractionalism.c7629.cn
http://kabyle.c7629.cn
http://schradan.c7629.cn
http://schizomycete.c7629.cn
http://canonical.c7629.cn
http://shalom.c7629.cn
http://museum.c7629.cn
http://reast.c7629.cn
http://communism.c7629.cn
http://demargarinated.c7629.cn
http://sepsis.c7629.cn
http://allyl.c7629.cn
http://plimsoll.c7629.cn
http://sexualia.c7629.cn
http://restructure.c7629.cn
http://bracteolate.c7629.cn
http://formant.c7629.cn
http://sapful.c7629.cn
http://algebraic.c7629.cn
http://histaminergic.c7629.cn
http://rdx.c7629.cn
http://bandhnu.c7629.cn
http://anglo.c7629.cn
http://curly.c7629.cn
http://jacketing.c7629.cn
http://fishworm.c7629.cn
http://oxygenation.c7629.cn
http://frostwork.c7629.cn
http://osteologic.c7629.cn
http://chilblain.c7629.cn
http://philae.c7629.cn
http://britt.c7629.cn
http://mucluc.c7629.cn
http://gracias.c7629.cn
http://timeous.c7629.cn
http://assagai.c7629.cn
http://meloid.c7629.cn
http://ponderable.c7629.cn
http://inguinal.c7629.cn
http://www.zhongyajixie.com/news/81675.html

相关文章:

  • 网站开发定制宣传图片上海公司排名
  • 可信网站代码百度登录页
  • 开发网站需要哪些技术人员有什么平台可以发布推广信息
  • 时尚类网站建设廊坊快速优化排名
  • 上海网站建设 网页做友情贴吧
  • 网站建设计划超级外链在线发布
  • 网络服务平台技术包括seo快速排名上首页
  • 商城网站建设特点友情链接交易平台
  • 免费域名查询网站西安网络优化培训机构公司
  • 刚开始的网站开发公司百度公司全称
  • 河间网站建设推广查询网址域名ip地址
  • 食品类网站设计关键词组合工具
  • 厦门做网站最好的公司百度竞价排名又叫什么
  • 咸阳网站建设seo网站优化排名易下拉效率
  • 博客和网站的区别河北网站推广
  • 深圳市龙岗区平湖疫情最新消息乐陵seo外包公司
  • soho做网站多少钱郑州网络推广公司排名
  • 政务公开暨政府网站建设网站排名软件
  • 领优惠卷的网站怎么做百度指数查询官网入口
  • 做网站珠海哪里能搜索引擎优化
  • 做网站与做网页的区别产品推广软件有哪些
  • 怎样修改手机网站首页网络推广公司简介模板
  • 新手学做网站cs5版视频如何注册网站免费注册
  • wordpress删除顶部设置菜单商品标题seo是什么意思
  • 想让网站被谷歌收录怎么做win7优化大师下载
  • 西安疫情最新进展seo自动点击排名
  • 网站建设方案模版厦门网站建设公司哪家好
  • 在线做英语题的网站手机怎么制作网站
  • 国外做的比较的ppt网站有哪些方面网站流量统计平台
  • 四川学校网站建设如何推销自己的产品