当前位置:网站首页>Wait (), notify (), notifyAll (), sleep (), condition, await (), signal()
Wait (), notify (), notifyAll (), sleep (), condition, await (), signal()
2022-06-25 11:20:00 【User 9854323】
wait()、notify() and notifyAll() yes Object class The method in From the text description of these three methods, we can know the following information : 1) wait()、notify() and notifyAll() Methods are local methods , And for final Method , Can't be rewritten . 2) Call... Of an object wait() Method to block the current thread , And the current thread must own this object monitor( Immediate lock ) 3) Call... Of an object notify() Method can wake up a waiting object monitor The thread of , If there are multiple threads waiting for this object monitor, You can only wake up one of the threads ; 4) call notifyAll() Method can wake up all waiting for this object monitor The thread of ; 5 ) If you call the wait() Method , The current thread must have the monitor( Immediate lock ), So call wait() Method must be in synchronization block or synchronization method (synchronized Block or synchronized Method ). 6 ) Call... Of an object wait() Method , Equivalent to having the current thread hand over the object monitor, Then enter the waiting state , Wait for the lock of this object to be acquired again later (Thread Class sleep The thread pauses the execution of the method for a period of time , This gives other threads a chance to continue , But it doesn't release the object lock ); 7 ) Call... Of an object notify() Method , The current thread must also own this object monitor, So call notify() Method must be in synchronization block or synchronization method (synchronized Block or synchronized Method ).
Condition Is in java 1.5 It's not until now , It's used to replace the traditional Object Of wait()、notify() Realize the cooperation between threads , Compared with Object Of wait()、notify(), Use Condition Of await()、signal() It is safer and more efficient to realize the cooperation between threads in this way . Therefore, it is generally recommended to use Condition.
1 ) Condition It's an interface , The basic method is await() and signal() Method ; 2 ) Condition Depend on Lock Interface , Generate a Condition The basic code is lock.newCondition() 3 ) call Condition Of await() and signal() Method , Must be in lock Within protection , That is to say, it must be lock.lock() and lock.unlock Can only be used between
Conditon Medium await() Corresponding Object Of wait(); Condition Medium signal() Corresponding Object Of notify(); Condition Medium signalAll() Corresponding Object Of notifyAll()
边栏推荐
- 金仓数据库 KingbaseES 插件ftutilx
- GaussDB others内存比较高的场景
- 【上云精品】节能提效!加速纺织业“智造”转型
- Jincang KFS data cascade scenario deployment
- Arrays. asList()
- [observation] objectscale: redefining the next generation of object storage, reconstruction and innovation of Dell Technology
- GaussDB 如何统计用户sql的响应时间
- A program reflecting the characteristics of C language program structure
- Crawler scheduling framework of scratch+scratch+grammar
- C disk uses 100% cleaning method
猜你喜欢

JVM 原理简介

c盘使用100%清理方法

牛客网:分糖果问题
![[file inclusion vulnerability-04] classic interview question: how to getshell when a website is known to have only local file inclusion vulnerability?](/img/28/ab02d38bde47053b155e0545b47039.png)
[file inclusion vulnerability-04] classic interview question: how to getshell when a website is known to have only local file inclusion vulnerability?

An interesting logic SRC mining

Redis6笔记02 配置文件,发布和订阅,新数据类型,Jedis操作

Compilation of learning from Wang Shuang (1)

今天16:00 | 中科院计算所研究员孙晓明老师带大家走进量子的世界

杭州/北京内推 | 阿里达摩院招聘视觉生成方向学术实习生(人才计划)

仿真与烧录程序有哪几种方式?(包含常用工具与使用方式)
随机推荐
Spannable and editable, spannablestring and spannablestring
How to realize the rich text editor function of mobile terminal
手机上股票开户安全吗?找谁可以开户啊?
龙书虎书鲸书啃不动?试试豆瓣评分9.5的猴书
Daily 3 questions (3) - check whether integers and their multiples exist
FPGA基于VGA显示字符及图片
CMU提出NLP新范式—重构预训练,高考英语交出134高分
Daily 3 questions (2) - find out the lucky numbers in the array
MySQL synchronous data configuration and shell script implementation
zabbix分布式系统监控
如何实现移动端富文本编辑器功能
Ladder Side-Tuning:预训练模型的“过墙梯”
Software testing to avoid being dismissed during the probation period
Kingbasees plug-in ftutilx of Jincang database
Coscon'22 lecturer solicitation order
基于SSH的高校实验室物品管理信息系统的设计与实现 论文文档+项目源码及数据库文件
中國信通院沈瀅:字體開源協議——OFL V1.1介紹及合規要點分析
Jincang KFS data centralized scenario (many to one) deployment
Advanced single chip microcomputer -- development of PCB (2)
数据库系列:MySQL索引优化总结(综合版)