当前位置:网站首页>线程的调度(优先级)
线程的调度(优先级)
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
边栏推荐
- PHP generates short links: convert numbers to letters and letters to numbers
- vslam PPT
- Convert object to URL
- 有意思的js 代码
- Vowel substring in statistical string of leetcode simple problem
- [learning] audio and video development from scratch (9) -- nuplayer
- Smart business card applet business card details page function implementation key code
- Comparison of indoor positioning methods of several intelligent robots
- 扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
- How to read books and papers
猜你喜欢
ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建
CSV column extract column extraction
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
How to read books and papers
The whole house intelligence bet by the giant is driving the "self revolution" of Hisense, Huawei and Xiaomi
Positioning of high precision welding manipulator
Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
Rearranging log files for leetcode simple question
thinkphp6+jwt 实现登录验证
扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
随机推荐
Situational leaders - Chapter 7, solving performance problems
监控智能回放是什么,如何使用智能回放查询录像
岛屿的个数
WordPress love navigation theme 1.1.3 simple atmosphere website navigation source code website navigation source code
浏览器中的 Kubernetes 和 IDE | 交互式学习平台Killercoda
LeetCode15. Sum of three
使用JWT生成与解析Token
单点登录 SSO
CGM优化血糖监测管理——移宇科技亮相四川省国际医学交流促进会
Convert object to URL
Planification du mouvement du manipulateur dans l'assemblage 3c
Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
Canvas learning Chapter 1
Kubernetes in browser and IDE | interactive learning platform killercoda
扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
关于ORB——SLAM运行中关键帧位置越来越近的异常说明
Discussion on ES6 tail tune optimization
NFT ecological development of Ignis public chain: unicorn Donation and development of Art
Sword finger offer Day24 math (medium)
thinkphp6+jwt 实现登录验证