当前位置:网站首页>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
边栏推荐
- Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
- 治疗TensorFlow后遗症——简单例子记录torch.utils.data.dataset.Dataset重写时的图片维度问题
- Practical operation - Nacos installation and configuration
- 线性代数第二章-矩阵及其运算
- Numpy common function table sorting of data processing
- 去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
- Understanding and use of tp50, tp90 and tp99
- SQL optimization best practices
- JDBC connection database
- IO multiplexing of 09 redis
猜你喜欢
Pytorch learning record (XII): learning rate attenuation + regularization
PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码
Automatic control (Han min version)
PyQy5学习(二):QMainWindow+QWidget+QLabel
线性代数第三章-矩阵的初等变换与线性方程组
Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
Configure domestic image accelerator for yarn
自动控制原理知识点整合归纳(韩敏版)
String notes
線性代數第一章-行列式
随机推荐
12. Monkeys climb mountains
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
20 excellent plug-ins recommended by idea
Kingdee EAS "general ledger" system calls "de posting" button
Algèbre linéaire chapitre 2 - matrice et son fonctionnement
The problem that the page will refresh automatically after clicking the submit button on the form is solved
数字图像处理基础(冈萨雷斯)二:灰度变换与空间滤波
Problems and solutions of database migration
What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
Solution record of slow access speed of SMB service in redhat6
去噪论文阅读——[CVPR2022]Blind2Unblind: Self-Supervised Image Denoising with Visible Blind Spots
Anaconda安装PyQt5 和 pyqt5-tools后没有出现designer.exe的问题解决
DBCP usage
RedHat realizes keyword search in specific text types under the directory and keyword search under VIM mode
How to grow at work
Generate excel template (drop-down selection, multi-level linkage)
对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
In depth source code analysis servlet first program
Rsync for file server backup
MySQL best practices for creating tables