首页 > 其他分享 >BlockingQueue---SynchronousQueue

BlockingQueue---SynchronousQueue

时间:2023-10-31 11:13:22浏览次数:31  
标签:queue code thread SynchronousQueue --- 队列 线程 BlockingQueue

概述

  

  A {@linkplain BlockingQueue blocking queue} in which each insert operation must wait for a corresponding remove operation by another thread, and vice versa.
  A synchronous queue does not have any internal capacity, not even a capacity of one.
  You cannot {@code peek} at a synchronous queue because an element is only present when you try to remove it; you cannot insert an element (using any method) unless another thread is trying to remove it; you cannot iterate as there is nothing to iterate.
  The <em>head</em> of the queue is the element that the first queued inserting thread is trying to add to the queue; if there is no such queued thread then no element is available for removal and {@code poll()} will return {@code null}.
  For purposes of other {@code Collection} methods (for example {@code contains}), a {@code SynchronousQueue} acts as an empty collection.
  This queue does not permit {@code null} elements.

    

    一个 BlockingQueue,其中每个插入操作 都必须等待另一个线程执行相应的删除操作,反之亦然。
    同步队列没有任何内部容量,甚至没有 1 的容量。
    您不能peek同步队列,因为只有在您尝试删除元素时才存在该元素; 你不能插入一个元素,除非另一个线程试图删除它;你不能迭代,因为没有什么可迭代的。
    队列<em>头部</em>是第一个排队的插入线程尝试添加到队列中的元素;如果没有这样的排队线程,则没有元素可供删除,{@code poll()} 将返回 {@code null}。
    对于其他 {@code Collection} 方法(例如 {@code contains}),{@code SynchronousQueue} 充当空集合。
    此队列不允许 {@code null} 元素;

 

  Synchronous queues are similar to rendezvous channels used in CSP and Ada.
  They are well suited for handoff designs, in which an object running in one thread must sync up with an object running in another thread in order to hand it some information, event, or task.

    

    同步队列类似于 CSP 和 Ada 中使用的集合通道。
    它们非常适合切换设计,在这种设计中,在一个线程中运行的对象必须与在另一个线程中运行的对象同步,以便将一些信息、事件或任务传递给它;

 

  This class supports an optional fairness policy for ordering waiting producer and consumer threads.
  By default, this ordering is not guaranteed.
  However, a queue constructed with fairness set to {@code true} grants threads access in FIFO order.

    

    此类支持可选的公平性策略,用于对等待的生产者和使用者线程进行排序。
    默认情况下,不保证此排序。
    但是,在公平性设置为 {@code true} 的情况下构造的队列按 FIFO 顺序授予线程访问权限;

标签:queue,code,thread,SynchronousQueue,---,队列,线程,BlockingQueue
From: https://www.cnblogs.com/anpeiyong/p/17799788.html

相关文章

  • 【面试题】前端面试复习6---性能优化
    性能优化一、性能指标要在Chrome中查看性能指标,可以按照以下步骤操作:打开Chrome浏览器,并访问你想要测试的网页。使用快捷键F12或右键点击页面并选择“检查”,打开开发者工具。在开发者工具中,切换到“Performance”(性能)选项卡。点击开始录制按钮,即红色的圆点按钮。开始加载页......
  • 2023年第四季度DAMA-CDGA/CDGP数据治理认证报名开始啦!
    DAMA认证为数据管理专业人士提供职业目标晋升规划,彰显了职业发展里程碑及发展阶梯定义,帮助数据管理从业人士获得企业数字化转型战略下的必备职业能力,促进开展工作实践应用及实际问题解决,形成企业所需的新数字经济下的核心职业竞争能力。DAMA是数据管理方面的认证,帮助数据从业者提升......
  • React Native 页面调试工具 react-native-vdebug
    yarnaddreact-native-vdebugimportReactfrom'react'import{createNativeStackNavigator}from'@react-navigation/native-stack'import{getRouter}from'./config'import{ErrorBoundary}from'../component/light......
  • 2023第四季北京/上海/广州/深圳DAMA-CDGA/CDGP数据治理认证报名
    DAMA认证为数据管理专业人士提供职业目标晋升规划,彰显了职业发展里程碑及发展阶梯定义,帮助数据管理从业人士获得企业数字化转型战略下的必备职业能力,促进开展工作实践应用及实际问题解决,形成企业所需的新数字经济下的核心职业竞争能力。DAMA是数据管理方面的认证,帮助数据从业者提升......
  • 面向对象进阶19.1.1-接口中的默认方法
    JDK-8以后,Java允许在接口中定义默认方法,需要使用关键词default修饰。作用:解决接口升级的问题。定义格式----publicdefault返回值类型函数名(参数){};例如:-------'publicdefaultvoidshow()`下面是代码:点击查看代码//接口:publicinterfaceInterA{publicabstract......
  • CSP-S 2023 邮寄
    前言先咕着,等什么时候心情好了再继续写。省流云斗OJ:T1100,T235,T3100,T40正文周五中午出发去九江,做的是高铁?路上看完了三本小说(但其实都是之前看过的),终于是到了九江。做出租车做了一个小时,收费73RMB(好贵QAQ),但是后来好像报销了???晚上和小A住一起(想吃外星人酿的苹果了)。晚......
  • Opencascad开发(C++)-数据类型转换-Shape、Verterx和gp_pnt的转化
    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录1、前言2、TopoDS_Shape与TopoDS_Vertex的转换2.1TopoDS_Shape到TopoDS_Vertex2.2TopoDS_Vertex到TopoDS_Shape3、TopoDS_Vertex与gp_Pnt3.1TopoDS_Vertex到gp_Pnt3.2gp_Pnt到TopoDS_Vertex1、前言在Open......
  • Opencascad(C++)-建模-创建有界直线段
    文章目录1、前言2、用gp_Lin创建一条直线2.1gp_Lin类成员函数2.2创建一条直线2.3运行结果3、创建一条有界的直线段3.1功能说明3.2函数说明3.2创建直线段的代码3.3测试效果1、前言在Opencascad开发时,经常会遇到创建直线的情况,采用gp_Line创建的直线段是无界的,如果想创建......
  • 【ROS2机器人入门到实战】学会使用RVIZ2-TF组件
    2.可视化坐标变换写在前面当前平台文章汇总地址:ROS2机器人从入门到实战获取完整教程及配套资料代码,请关注公众号<鱼香ROS>获取教程配套机器人开发平台:两驱版|四驱版为方便交流,搭建了机器人技术问答社区:地址fishros.org.cn运行上节课的示例,打开终端输入rviz2,打开rviz2,我们尝试在rv......
  • Kafka-生产者、broker、消费者的调优参数总结
     生产环境下,为了尽可能提升Kafka的整体吞吐量,可以对Kafka的相关配置参数进行调整,以达到提升整体性能的目的。本文主要从Kafka的不同组件出发,讲解各组件涉及的配置参数和参数含义。一、生产者(producer.properties或者代码中)1、acks:Producer需要Leader确认的Producer请求的应答......