当前位置:网站首页>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
边栏推荐
- [original] use system Text. JSON formats the JSON string
- L2-023 图着色问题 (25 分)(图的遍历)
- Production practice elk
- Illegal character in scheme name at index 0:
- Notes d'apprentissage oneflow: de functor à opexprinterpreter
- Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
- 在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
- DJ music management software pioneer DJ rekordbox
- EmuElec 编译总结
- 小女孩行走
猜你喜欢
计算神经网络推理时间的正确方法
Share the office and improve the settled experience
Latex paper typesetting operation
node安装
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
Redis Desktop Manager for Mac
ONEFLOW learning notes: from functor to opexprinter
Failed to download esp32 program, prompting timeout
Open services in the bottom bar of idea
First principle mind map
随机推荐
Failed to prepare device for development
[boutique] using dynamic agent to realize unified transaction management II
Introduction to GUI programming swing
cadence的工艺角仿真、蒙特卡洛仿真、PSRR
Idea package jar file
Data visualization: use Excel to make radar chart
Arbre de dépendance de l'emballage des ressources
Strength comparison vulnerability of PHP based on hash algorithm
Learn SQL injection in sqli liabs (Level 11 ~ level 20)
About CIN, scanf and getline, getchar, CIN Mixed use of getline
Initial experience of talent plan learning camp: communication + adhering to the only way to learn open source collaborative courses
Complete binary search tree (30 points)
Go language self-study series | golang method
L2-023 图着色问题 (25 分)(图的遍历)
Latex paper typesetting operation
汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告
求简单类型的矩阵和
是否同一棵二叉搜索树 (25 分)
Star Trek强势来袭 开启元宇宙虚拟与现实的梦幻联动
Play with binary tree (25 points)