当前位置:网站首页>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
边栏推荐
- GUI编程简介 swing
- 玩转二叉树 (25 分)
- What is augmented reality technology? Where can it be used?
- Experimental report on analysis of overflow vulnerability of assembly language and reverse engineering stack
- MySQL小練習(僅適合初學者,非初學者勿進)
- Whether the same binary search tree (25 points)
- MySQL small exercise (only suitable for beginners, non beginners are not allowed to enter)
- Common errors of VMware building es8
- BK3633 规格书
- Concave hull acquisition method based on convex hull of point cloud
猜你喜欢

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

LLVM之父Chris Lattner:编译器的黄金时代

调包求得每个样本的k个邻居

MySQL查询两张表属性值非重复的数据

Production practice elk

搞不懂时间、时间戳、时区,快来看这篇

2021 Li Hongyi's adaptive learning rate of machine learning

Valgrind and kcache grind use run analysis

Project upload part

Bk3633 specification
随机推荐
ONEFLOW learning notes: from functor to opexprinter
Play with binary tree (25 points)
Talent Plan 学习营初体验:交流+坚持 开源协作课程学习的不二路径
What is augmented reality technology? Where can it be used?
Flink reads MySQL and PgSQL at the same time, and the program will get stuck without logs
On array replication
Consensus Token:web3.0生态流量的超级入口
Share the office and improve the settled experience
L2-024 部落 (25 分)(并查集)
Multi view depth estimation by fusing single view depth probability with multi view geometry
GUI编程简介 swing
npm报错 :operation not permitted, mkdir ‘C: \Program Files \node js \node_ cache _ cacache’
Idea package jar file
共享办公室,提升入驻体验
The K neighbors of each sample are obtained by packet switching
K210 learning notes (II) serial communication between k210 and stm32
Arbre de dépendance de l'emballage des ressources
求简单类型的矩阵和
MySQL查询两张表属性值非重复的数据
Withholding agent