当前位置:网站首页>LockSupport. Park and unpark, wait and notify
LockSupport. Park and unpark, wait and notify
2022-04-23 06:21:00 【commonBean】
LockSupport.park Method to block the current thread ,unpark You can resume its operation .
LockSupport And every thread that uses it has a license (permit) relation .permit amount to 1,0 The switch of , The default is 0, Call once unpark Just add 1 become 1, Call once park Will be spending permit, Also is to 1 become 0, meanwhile park Return immediately . Call again park Will become block( because permit by 0 了 , It's going to get stuck here , until permit Turn into 1), Call at this time unpark Will be able to permit Set as 1. Each thread has an associated permit, permit At most one , Repeated calls to unpark It won't accumulate .
park()/unpark() The underlying principle is “ Binary semaphore ”, You can think of it as if it had only one license Semaphore, But this semaphore is executing repeatedly unpark() There will be no more licenses , There is only one license at most .
Before one of the following three situations occurs , The current thread will be dormant :
- Some other thread calls... With the current thread as the target unpark.
- Another thread interrupts the current thread .
- The call illogically ( That is, without any reason ) return .
Thread.sleep() Will not release the lock of possession ,LockSupport.park() The lock held by the current thread will not be released ;Object.wait() Will release the lock of possession .
Thread.sleep() Time must be passed in , Can't wake up from the outside , I can only wake up myself ;Object.wait() Can pass but not pass , With time , If not notify, It will wake up automatically when it's time , No transmission means it's stuck , Need another thread to use Object.notify() Wake up the ;LockSupport.park() Method can be called by another thread LockSupport.unpark() Method wake up ;
If in wait() It was done before notify() Will throw out IllegalMonitorStateException abnormal ; If in park() It was done before unpark(), Threads will not be blocked , Just skip park(), Continue with what follows ;
版权声明
本文为[commonBean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533052852.html
边栏推荐
- 去噪论文阅读——[CVPR2022]Blind2Unblind: Self-Supervised Image Denoising with Visible Blind Spots
- Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
- A sharp tool to improve work efficiency
- MySQL basic madness theory
- The attendance client date of K / 3 wise system can only be selected to 2019
- 線性代數第二章-矩陣及其運算
- 8. Integer Decomposition
- RPC must know and know
- DBCP usage
- Implementation of displaying database pictures to browser tables based on thymeleaf
猜你喜欢

Illustrate the significance of hashcode

检测技术与原理

Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)

PyQt5学习(一):布局管理+信号和槽关联+菜单栏与工具栏+打包资源包

深入理解去噪论文——FFDNet和CBDNet中noise level与噪声方差之间的关系探索
![如何利用对比学习做无监督——[CVPR22]Deraining&[ECCV20]Image Translation](/img/33/780b80693f70112eebc10941f7c134.png)
如何利用对比学习做无监督——[CVPR22]Deraining&[ECCV20]Image Translation

Contrôle automatique (version Han min)

Pytoch -- data loading and processing

In depth source code analysis servlet first program

IO multiplexing of 09 redis
随机推荐
Linear algebra Chapter 1 - determinant
卡尔曼滤波与惯性组合导航
Anaconda
Create enterprise mailbox account command
Fundamentals of SQL: first knowledge of database and SQL - installation and basic introduction - Alibaba cloud Tianchi
EditorConfig
Pyqt5 learning (I): Layout Management + signal and slot association + menu bar and toolbar + packaging resource package
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
Preparedstatement prevents SQL injection
7.Domino piling
Example of reentrant lock thread waiting to wake up
无监督去噪——[TMI2022]ISCL: Interdependent Self-Cooperative Learning for Unpaired Image Denoising
A general U-shaped transformer for image restoration
Use of multithreaded executors
線性代數第二章-矩陣及其運算
Numpy common function table sorting of data processing
Kingdee EAS "general ledger" system calls "de posting" button
Pytorch学习记录(三):神经网络的结构+使用Sequential、Module定义模型
The attendance client date of K / 3 wise system can only be selected to 2019