当前位置:网站首页>Pessimistic lock and optimistic lock of multithreading
Pessimistic lock and optimistic lock of multithreading
2022-07-03 05:13:00 【A wild man about to succeed】
process : The smallest unit of resource allocation
No one will wait for anyone between threads . Who is the first to get cpu Whoever calculates first

Time slice rotation algorithm :cpu The time allocated to each thread that it can execute . Writing memory needs to occupy the bus 64bit
Multithreaded code
package wangyi0820;
//z Main method
public class MultiDemo {
public static void main(String[] args) {
ThreadNew tn1 = new ThreadNew(1);
ThreadNew tn2 = new ThreadNew(2);
tn1.start();
tn2.start();
}
}
package wangyi0820;
public class ThreadNew extends Thread {
private int falge;
public ThreadNew(int falge) {
this.falge = falge;
}
public void run() {
if (falge == 1) {
System.out.println("run1() Method execution ");
} else {
System.out.println("run2() Method execution ");
}
}
}
lock
Pessimistic locking ( Also known as locking )
Don't let users read , Don't let users write , Only when one thread finishes writing can another thread read and write

Optimism lock ( Also known as semaphore )
Let users read , But don't let users write , Yes Version number , Wrong version , Just redo the calculation . amount to Gitee Branches and mainlines

边栏推荐
- Webapidom get page elements
- Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
- Interface frequency limit access
- 1110 complete binary tree (25 points)
- Make your own dataset
- Review the configuration of vscode to develop golang
- BIO、NIO、AIO区别
- Principles of BTC cryptography
- Cross platform plug-in flutter for displaying local notifications_ local_ notifications
- Congratulations to musk and NADELLA on their election as academicians of the American Academy of engineering, and Zhang Hongjiang and Fang daining on their election as foreign academicians
猜你喜欢

Go practice -- design patterns in golang's singleton

Introduction to deep learning (II) -- univariate linear regression

2022-02-11 daily clock in: problem fine brush

【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)

Overview of basic knowledge of C language

es7创建索引容易犯的错误

大学校园IP网络广播-厂家基于校园局域网的大学校园IP广播方案设计指南

Source insight garbled code solution

How to connect the network: Chapter 2 (Part 1): a life cycle of TCP connection | CSDN creation punch in

appium1.22. Appium inspector after X version needs to be installed separately
随机推荐
[basic grammar] Snake game written in C language
Dynamic programming - related concepts, (tower problem)
Redis Introduction et explication des types de données
Interface frequency limit access
Class loading mechanism (detailed explanation of the whole process)
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
【批处理DOS-CMD命令-汇总和小结】-CMD窗口的设置与操作命令-关闭cmd窗口、退出cmd环境(exit、exit /b、goto :eof)
Appium 1.22. L'Inspecteur appium après la version X doit être installé séparément
Detailed explanation of yolov5 training own data set
112 stucked keyboard (20 points)
Self introduction and objectives
1095 cars on campus (30 points)
JS scope
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
[set theory] relationship properties (common relationship properties | relationship properties examples | relationship operation properties)
Detailed explanation of the output end (head) of yolov5 | CSDN creation punch in
leetcode435. Non overlapping interval
Shuttle + alluxio accelerated memory shuffle take-off
Shallow and first code
leetcode452. Detonate the balloon with the minimum number of arrows