当前位置:网站首页>线程的调度(优先级)
线程的调度(优先级)
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
边栏推荐
- Positioning of high precision welding manipulator
- 通过实现参数解析器HandlerMethodArgumentResolver接口来自定义注解
- 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
- 使用JWT生成与解析Token
- 情境领导者-第七章、解决绩效问题
- There are some problems when using numeric type to query string type fields in MySQL
- 搜一下导航完整程序源码
- Rotation function of leetcode medium problem
- PyQt5开发之QTableWidget表头自定义与美化(附源代码下载)
- 如何保护开源项目免遭供应链攻击-安全设计(1)
猜你喜欢

青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码

LeetCode中等题之旋转函数

一篇文章看懂变量提升(hoisting)

干货!以点为形:可微分的泊松求解器

Campus transfer second-hand market source code download

How to import Excel data in SQL server, 2019 Edition

Canvas learning Chapter 1

The simple problem of leetcode is to calculate the numerical sum of strings

Vowel substring in statistical string of leetcode simple problem

Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
随机推荐
单点登录 SSO
扎心了!一女子发朋友圈羡慕别人按时发工资被开除,连点赞的同事也一同被开除了...
Penetration test interview collection -- HVV---
js常用数组方法
Transformer-XL: Attentive Language ModelsBeyond a Fixed-Length Context 论文总结
英语课小记(四)
Draw a circle quickly in MATLAB (the one that can be drawn directly given the coordinates and radius of the center of the circle)
[effective go Chinese translation] function
Situational leaders - Chapter 7, solving performance problems
[untitled]
LeetCode简单题之重新排列日志文件
【无标题】
2022.4.11-4.17 AI industry weekly (issue 93): the dilemma of AI industry
An article understands variable lifting
Samsung, March to the west again
An idea plug-in that doesn't work, but can install X
[appium] encountered the problem of switching the H5 page embedded in the mobile phone during the test
Talk about the basic but not simple stock data
A simple theme of Typecho with beautiful appearance_ Scarfskin source code download
浏览器中的 Kubernetes 和 IDE | 交互式学习平台Killercoda