void java.lang.Object.notifyAll()

Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up. The threads will not run immediately. The thread that called notify() has to release the object's monitor first. Also, the threads still have to compete against other threads that try to synchronize on the same object.

This method can only be invoked by a thread which owns this object's monitor. A thread becomes owner of an object's monitor

  • by executing a synchronized method of that object;
  • by executing the body of a synchronized statement that synchronizes on the object;
  • by executing a synchronized static method if the object is of type Class.
Throws:
IllegalMonitorStateException - if the thread calling this method is not the owner of this object's monitor.
See Also:
notify
wait()
wait(long)
wait(long, int)
java.lang.Thread
作用:唤醒所有在object对象上调用wait()方法的线程,线程不一定会立即执行。调用了notify()方法的线程会首先释放object锁,而且线程仍然需要和其他线程竞争来同步同一个对象。此方法只能唤醒拥有对象锁的线程。一个对象要拥有一个对象锁,可以通过下面三个方法:
1.  执行此对象的一个同步方法
2.  执行同步此对象的方法块
3.  如果对象是Class类型,执行一个同步静态方法
抛出异常:IllegalMonitorStateException    如果调用notifyAll()的线程不是锁的拥有者

Object.notifyAll()的更多相关文章

  1. Java多线程Thread.yield(),thread.join(), Thread.sleep(200),Object.wait(),Object.notify(),Object.notifyAll()的区别

    Thread.yield(),在某个线程里调用Thread.yield(),会使这个线程由正在运行的running状态转变为等待cpu时间片的runable状态.join()是Thread类的一个非s ...

  2. Object中的wait,notify,notifyAll基本使用(转)

    让线程停止运行/睡眠的方法只有两个:Thread.sleep()或者obj.wait() 记住obj.nofity()并不能停止线程运行,因为notify虽然释放了锁,但依然会急促执行完synchro ...

  3. Java Object对象中的wait,notify,notifyAll的理解

    wait,notify,notifyAll 是定义在Object类的实例方法,用于控制线程状态,在线程协作时,大家都会用到notify()或者notifyAll()方法,其中wait与notify是j ...

  4. java中的wait(),notify(),notifyAll(),synchronized方法

    wait(),notify(),notifyAll()三个方法不是Thread的方法,而是Object的方法.意味着所有对象都有这三个方法,因为每个对象都有锁,所以自然也都有操作锁的方法了.这三个方法 ...

  5. Java并发编程:线程间协作的两种方式:wait、notify、notifyAll和Condition

    Java并发编程:线程间协作的两种方式:wait.notify.notifyAll和Condition 在前面我们将了很多关于同步的问题,然而在现实中,需要线程之间的协作.比如说最经典的生产者-消费者 ...

  6. Object窥探

    /* * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...

  7. java Object类学习

    /* * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETA ...

  8. Object.wait()与Object.notify()的用法

    http://www.cnblogs.com/xwdreamer/archive/2012/05/12/2496843.html 参考文献: object.wait()和object.notify() ...

  9. 【java线程系列】java线程系列之线程间的交互wait()/notify()/notifyAll()及生产者与消费者模型

    关于线程,博主写过java线程详解基本上把java线程的基础知识都讲解到位了,但是那还远远不够,多线程的存在就是为了让多个线程去协作来完成某一具体任务,比如生产者与消费者模型,因此了解线程间的协作是非 ...

随机推荐

  1. [求助] win7 x64 封装 出现 Administrator.xxxxx 的问题

    [求助] win7 x64 封装 出现 Administrator.xxxxx 的问题 jacky_qu 发表于 2014-9-3 23:34:37 https://www.itsk.com/thre ...

  2. Python’s SQLAlchemy vs Other ORMs[转发 2]Storm

    Storm Storm is a Python ORM that maps objects between one or more databases and Python. It allows de ...

  3. C#设置通过代理访问ftp服务器

    // 创建FTP连接 private FtpWebRequest CreateFtpWebRequest(string uri, string requestMethod) { FtpWebReque ...

  4. 安装.Net Framework3.5

    Dism /online /enable-feature /featurename:NetFX3 /All /Source:V:\sources\sxs /LimitAccess

  5. 安装numpy

    为了运行机器学习书上的实例,安装numpy.照着网上教程安装的,网上教程 1)下载numpy包 下载地址:https://pypi.python.org/pypi/numpy/#downloads 自 ...

  6. MySQL ERROR 1005: Can't create table (errno: 150)的错误解决办法

    在mysql 中建立引用约束的时候会出现MySQL ERROR 1005: Can't create table (errno: 150)的错误信息结果是不能建立 引用约束. 出现问题的大致情况 1. ...

  7. TranslateAnimation 运行动画后实际位置不正确问题

    最近在调试android 动画时候发现一个很奇怪问题,网上搜索都说TranslateAnimation 动画运行后,实际位置要在动画结束的监听里面重新设置才会正确,不然物体位置还是在原位. 我根据网上 ...

  8. C++语法-指针 (1)

    <C++程序设计> 谭浩强  清华大学出版社 2016-08-03 1.P167 一般的C++编译系统为每个指针变量分配4个字节的存储单元,用来存放变量的地址. 2.P169 .cpp文件 ...

  9. IT求职中,笔试、面试的算法准备

    PS:此文章为转载,源地址:http://www.newsmth.net/nForum/#!article/CoderInterview/849     作者应该是在美国进行的笔试面试,感觉面试的的公 ...

  10. 最近在做外贸网站的时候,需要大量的字体来充实页面,就学习了怎么引用Google Fonts

    第一步,FQ进入谷歌官方字体网站:https://fonts.google.com  妥妥的. 第二步,点击你所选择字体演示块的右上角的加号,然后你所选择的字体会形成引用链接以及你所要写的css样式. ...