当前位置:网站首页>Thread scheduling (priority)
Thread scheduling (priority)
2022-04-23 09:03:00 【z754916067】
Catalog
Scheduling of threads
Strategy
Preemptive : High priority thread preemption CPU
Scheduling method
- Form a first in first out queue for threads with the same priority ( First come, first serve ), Using time slice strategy .
- For high priority , Preemptive strategy using priority scheduling
The priority level of the thread
Three constants :
- MAX_PRIORITY:10
- MIN_PRIORITY:1
- NORM_PRIORITY:5 Default priority
Function method
- getPriority(): Returns the thread priority
- setPriority(int newPriority): Change the priority of a thread
explain
Inherits the priority of the parent thread when the thread is created
Low priority is only a low probability of obtaining scheduling , It doesn't have to be called after a high priority thread .
Code : Create three windows to sell tickets total 100 Zhang
class MyWindow extends Thread{
// ticket
private static int ticket = 100;
@Override
public void run() {
while (true){
if(ticket>0){
System.out.println(getName()+": Selling tickets , The ticket number is :"+ticket);
ticket--;
}else break;
}
}
}
public class WindowTest {
public static void main(String[] args) {
MyWindow t1 = new MyWindow();
MyWindow t2 = new MyWindow();
MyWindow t3 = new MyWindow();
t1.setName(" window 1");
t2.setName(" window 2");
t3.setName(" window 3");
t1.start();
t2.start();
t3.start();
}
}
There are thread safety issues
版权声明
本文为[z754916067]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230722125231.html
边栏推荐
- Research purpose, construction goal, construction significance, technological innovation, technological effect
- Illegal character in scheme name at index 0:
- LLVM之父Chris Lattner:编译器的黄金时代
- 基于点云凸包的凹包获取方法
- 2022-04-22 openebs cloud native storage
- How to read excel table to database
- Rembg split mask
- 2021李宏毅机器学习之Adaptive Learning Rate
- Harbor enterprise image management system
- Data visualization: use Excel to make radar chart
猜你喜欢

First principle mind map

Notes on xctf questions

计算神经网络推理时间的正确方法

Arbre de dépendance de l'emballage des ressources

To remember the composition ~ the pre order traversal of binary tree

Learn SQL injection in sqli liabs (Level 11 ~ level 20)

npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’

Study notes of deep learning (8)

Idea package jar file

Valgrind and kcache grind use run analysis
随机推荐
Open services in the bottom bar of idea
web页面如何渲染
Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
PLC point table (register address and point table definition) cracking detection scheme -- convenient for industrial Internet data acquisition
Use include in databinding
Four pictures to understand some basic usage of Matplotlib
Illegal character in scheme name at index 0:
错误: 找不到或无法加载主类
基于ThinkPHP5版本TRC20-资金归集解决方案
【原创】使用System.Text.Json对Json字符串进行格式化
L2-023 graph coloring problem (25 points) (graph traversal)
Consensus Token:web3.0生态流量的超级入口
About CIN, scanf and getline, getchar, CIN Mixed use of getline
Data visualization: use Excel to make radar chart
Is Zhongyan futures safe and reliable?
Consensus Token:web3. 0 super entrance of ecological flow
Cadence process angle simulation, Monte Carlo simulation, PSRR
小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab
小女孩行走
ONEFLOW learning notes: from functor to opexprinter