当前位置:网站首页>线程的调度(优先级)
线程的调度(优先级)
2022-04-23 07:22:00 【z754916067】
线程的调度
策略
抢占式:高优先级的线程抢占CPU
调度方法
- 对同优先级线程组成先进先出队列(先到先服务),使用时间片策略。
- 对高优先级,使用优先调度的抢占式策略
线程的优先级等级
三个常量:
- MAX_PRIORITY:10
- MIN_PRIORITY:1
- NORM_PRIORITY:5 默认的优先级
函数方法
- getPriority():返回线程优先级
- setPriority(int newPriority):改变线程的优先级
说明
线程创建时继承父线程的优先级
低优先级只是获得调度的概率低,并非一定是在高优先级线程之后才被调用。
代码:创建三个窗口卖票 总数100张
class MyWindow extends Thread{
//票
private static int ticket = 100;
@Override
public void run() {
while (true){
if(ticket>0){
System.out.println(getName()+":卖票,票号为:"+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("窗口1");
t2.setName("窗口2");
t3.setName("窗口3");
t1.start();
t2.start();
t3.start();
}
}
存在线程安全问题
版权声明
本文为[z754916067]所创,转载请带上原文链接,感谢
https://blog.csdn.net/z754916067/article/details/124350870
边栏推荐
- ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建
- Qt利用QtXlsx操作excel文件
- 监控智能回放是什么,如何使用智能回放查询录像
- vslam PPT
- 青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
- Community group purchase applet source code + interface DIY + nearby leader + supplier + group collage + recipe + second kill + pre-sale + distribution + live broadcast
- stm32以及freertos 堆栈解析
- Online yaml to XML tool
- 为什么会存在1px问题?怎么解决?
- Qt读取路径下所有文件或指定类型文件(含递归、判断是否为空、创建路径)
猜你喜欢
[untitled]
Smart business card applet business card details page function implementation key code
nn.Module类的讲解
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
LeetCode简单题之重新排列日志文件
The annotation is self-defined by implementing the parameter parser handlermethodargumentresolver interface
Detailed explanation of ansible automatic operation and maintenance (I) installation and deployment, parameter use, list management, configuration file parameters and user level ansible operating envi
Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
thinkphp6+jwt 实现登录验证
监控智能回放是什么,如何使用智能回放查询录像
随机推荐
How to read books and papers
vslam PPT
396. Rotate Function
Comparison of indoor positioning technology
LeetCode簡單題之計算字符串的數字和
2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
1216_ MISRA_ C standard learning notes_ Rule requirements for control flow
社区团购小程序源码+界面diy+附近团长+供应商+拼团+菜谱+秒杀+预售+配送+直播
Campus transfer second-hand market source code download
如何保护开源项目免遭供应链攻击-安全设计(1)
每周leetcode - 06 数组专题 7~739~50~offer 62~26~189~9
微信小程序 catchtap=“toDetail“ 事件问题
LeetCode15. Sum of three
Depth of binary tree
Listed on the Shenzhen Stock Exchange: the market value is 5.2 billion yuan. Lu is the East and his daughter is American
AQS & ReentrantLock 实现原理
ASAN 极简原理
Compiling principle questions - with answers
WordPress爱导航主题 1.1.3 简约大气网站导航源码网址导航源码
Install MySQL for Ubuntu and query the average score