当前位置:网站首页>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
边栏推荐
- Web APIs exclusivity
- Sprintf formatter abnormal exit problem
- 50 practical applications of R language (36) - data visualization from basic to advanced
- Notes | numpy-11 Array operation
- ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
- Oracle SQL table data loss
- Notes | numpy-07 Slice and index
- Go language interface learning notes
- [develop wechat applet local storage with uni app]
- cookie session jwt
猜你喜欢
es7创建索引容易犯的错误
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
Introduction to deep learning (II) -- univariate linear regression
Detailed explanation of yolov5 training own data set
Common interview questions of microservice
BIO、NIO、AIO区别
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
Silent authorization login and registration of wechat applet
Go practice - gorilla / handlers used by gorilla web Toolkit
JS scope
随机推荐
My first Smartphone
1115 counting nodes in a BST (30 points)
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
[develop wechat applet local storage with uni app]
1119 pre- and post order traversals (30 points)
Notes | numpy-07 Slice and index
The IntelliJ platform completely disables the log4j component
Distinguish between releases and snapshots in nexus private library
Technical analysis of qianyuantong multi card aggregation router
ES7 easy mistakes in index creation
JS scope
Handler understands the record
Dynamic programming - related concepts, (tower problem)
1095 cars on campus (30 points)
1087 all roads lead to Rome (30 points)
Self introduction and objectives
Blog building tool recommendation (text book delivery)
Yolov5 model construction source code details | CSDN creation punch in
Introduction to deep learning (II) -- univariate linear regression
[backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times