一, 使用conditionQueue需要注意的一些点:

一个conditionQueue被多种Predicate condition 使用是很正常的,所以当一个wait的线程被唤醒的时候,很有可能它监听的条件并没有成功,所以在wait醒后,最好再次进行条件的判断.

一定要在wait前就对条件进行判断,因为如果一个条件已经是true了,然后再进行wait,很可能会导致Missed Signals,   

调用notify()比较危险,因为存在一个conditionQueue被多种Predicate condition 使用的情况,所以使用notify()可能会导致Missed Signals同样的问题,所以最好使用notifyAll() 这种的问题是,每次都notifyAll()可能会有过多的线程切换,会耗费性能

For all these reasons, when you wake up from  wait  you must test the condition predicate again, and go back to waiting
(or fail) if it is not yet true. Since you can wake up repeatedly  without your condition predicate being true, you must
therefore always call  wait  from within a loop, testing the condition predicate in each iteration. The canonical form for a
condition wait is shown in Listing 14.7.
Listing 14.7. Canonical Form for State­dependent Methods.
void stateDependentMethod() throws InterruptedException {
// condition predicate must be guarded by lock
synchronized(lock) {
while (!conditionPredicate())
lock.wait();
// object is now in desired state
}
}

When using condition waits ( Object.wait  or  Condition.await ):
• Always have a condition predicatesome test of object state that must hold before proceeding;
• Always test the condition predicate before calling  wait , and again after returning from  wait ;
• Always call  wait  in a loop;
• Ensure  that  the  state  variables  making  up  the  condition  predicate  are  guarded  by  the  lock  associated  with  the
condition queue;
• Hold the lock associated with the the condition queue when calling  wait ,  notify , or  notifyAll ; and
• Do not release the lock after checking the condition predicate but before acting on it.

Single  notify  can be used instead of  notifyAll  only when both of the following conditions hold:
• Uniform waiters. Only one condition predicate is associated with the condition queue, and each thread executes the
same logic upon returning from  wait ; and
• One‐in, one‐out. A notification on the condition variable enables at most one thread to proceed.

intrinsicConditionQueue笔记的更多相关文章

  1. git-简单流程(学习笔记)

    这是阅读廖雪峰的官方网站的笔记,用于自己以后回看 1.进入项目文件夹 初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 第一步,使用命令git add <file ...

  2. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  3. SQL Server技术内幕笔记合集

    SQL Server技术内幕笔记合集 发这一篇文章主要是方便大家找到我的笔记入口,方便大家o(∩_∩)o Microsoft SQL Server 6.5 技术内幕 笔记http://www.cnbl ...

  4. PHP-自定义模板-学习笔记

    1.  开始 这几天,看了李炎恢老师的<PHP第二季度视频>中的“章节7:创建TPL自定义模板”,做一个学习笔记,通过绘制架构图.UML类图和思维导图,来对加深理解. 2.  整体架构图 ...

  5. PHP-会员登录与注册例子解析-学习笔记

    1.开始 最近开始学习李炎恢老师的<PHP第二季度视频>中的“章节5:使用OOP注册会员”,做一个学习笔记,通过绘制基本页面流程和UML类图,来对加深理解. 2.基本页面流程 3.通过UM ...

  6. NET Core-学习笔记(三)

    这里将要和大家分享的是学习总结第三篇:首先感慨一下这周跟随netcore官网学习是遇到的一些问题: a.官网的英文版教程使用的部分nuget包和我当时安装的最新包版本不一致,所以没法按照教材上给出的列 ...

  7. springMVC学习笔记--知识点总结1

    以下是学习springmvc框架时的笔记整理: 结果跳转方式 1.设置ModelAndView,根据view的名称,和视图渲染器跳转到指定的页面. 比如jsp的视图渲染器是如下配置的: <!-- ...

  8. 读书笔记汇总 - SQL必知必会(第4版)

    本系列记录并分享学习SQL的过程,主要内容为SQL的基础概念及练习过程. 书目信息 中文名:<SQL必知必会(第4版)> 英文名:<Sams Teach Yourself SQL i ...

  9. 2014年暑假c#学习笔记目录

    2014年暑假c#学习笔记 一.C#编程基础 1. c#编程基础之枚举 2. c#编程基础之函数可变参数 3. c#编程基础之字符串基础 4. c#编程基础之字符串函数 5.c#编程基础之ref.ou ...

随机推荐

  1. bzoj1013球形空间

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1013 根据距离式子,两个点的话,两边平方再消掉x^2之后有: a1^2 - 2*a1*x1 ...

  2. IntelliJ IDEA 基础设置

    原文地址:IntelliJ IDEA 基础设置 博客地址:http://www.extlight.com 一.前言 IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,Intel ...

  3. emacs之配置gtags

    ~/emacsConfig/gtags-setting.el (if (eq system-type 'darwin) (add-to-list 'load-path "/usr/local ...

  4. Java-Runoob-高级教程-实例-环境设置实例:2.Java 实例 – Java 如何运行一个编译过的类文件?

    ylbtech-Java-Runoob-高级教程-实例-环境设置实例:2.Java 实例 – Java 如何运行一个编译过的类文件? 1.返回顶部 1. Java 实例 - 如何执行编译过 Java ...

  5. Web服务的实质介绍

    web应用的实质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端 Web应用程序是一种可以通过Web访问的应用程序,程序的最大好处是用 ...

  6. 常见的JS和CSS问题

    事件冒泡 DOM的事件冒泡机制和WPF很相似,DOM事件机制包含冒泡和捕获两种,按照topmost element->innermost element方向传递事件被称为捕获方式,而从inner ...

  7. django-redis缓存

    1.安装django依赖包 pip install djange-redis==4.8.0 2.配置文件settings  需要开启redis服务 sudo service redis start,否 ...

  8. CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点

    因为我的个人网站 restran.net 已经启用,博客园的内容已经不再更新.请访问我的个人网站获取这篇文章的最新内容,CentOS 环境下基于 Nginx uwsgi 搭建 Django 站点 以下 ...

  9. CommonDialog控件

    '要先单击“工程-部件”,显示“部件”对话框,将“Microsoft Common Dialog control 6.0(SP6)”选中,在工具栏就多出了一个CommonDialog控件图标,将其添加 ...

  10. 取消Eclipse的Error Reporting

    选择Preferences->General->Error Reporting,Send Mode选择Never send reports