当前位置:网站首页>线程的调度(优先级)
线程的调度(优先级)
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
边栏推荐
- The following program deletes n consecutive words starting from the ith character from the string str
- Comparison of indoor positioning methods of several intelligent robots
- Depth of binary tree
- [go] common concurrency model [generic version]
- PHP generates short links: convert numbers to letters and letters to numbers
- Kubernetes in browser and IDE | interactive learning platform killercoda
- Weekly leetcode - 06 array topics 7 ~ 739 ~ 50 ~ offer 62 ~ 26 ~ 189 ~ 9
- 如何保护开源项目免遭供应链攻击-安全设计(1)
- The simple problem of leetcode is to calculate the numerical sum of strings
- Planification du mouvement du manipulateur dans l'assemblage 3c
猜你喜欢

A simple theme of Typecho with beautiful appearance_ Scarfskin source code download

总线结构概述

LeetCode简单题之三除数

Community group purchase applet source code + interface DIY + nearby leader + supplier + group collage + recipe + second kill + pre-sale + distribution + live broadcast

thinkphp6+jwt 实现登录验证

Green apple film and television system source code film and television aggregation film and television navigation film and television on demand website source code

ansible自动化运维详解(一)ansible的安装部署、参数使用、清单管理、配置文件参数及用户级ansible操作环境构建

AAAI 2022招募讲者啦!!

clang 如何产生汇编文件

Thinkphp6 + JWT realizes login verification
随机推荐
The simple problem of leetcode is to calculate the numerical sum of strings
情境领导者-第七章、解决绩效问题
編譯原理題-帶答案
【Appium】测试时遇到手机内嵌H5页面的切换问题
Situational leaders - Chapter 7, solving performance problems
Ansible Automation Operation and Maintenance details (ⅰ) Installation and Deployment, Parameter use, list Management, Profile Parameters and user level ansible operating environment Construction
The annotation is self-defined by implementing the parameter parser handlermethodargumentresolver interface
Compiling principle questions - with answers
Samsung, March to the west again
WordPress love navigation theme 1.1.3 simple atmosphere website navigation source code website navigation source code
数据的删除和修改操作(mysql)
The third divisor of leetcode simple question
dmp引擎工作总结(2021,光剑)
LeetCode简单题之统计字符串中的元音子字符串
青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
Community group purchase applet source code + interface DIY + nearby leader + supplier + group collage + recipe + second kill + pre-sale + distribution + live broadcast
2022.4.11-4.17 AI行业周刊(第93期):AI行业的困局
为什么会存在1px问题?怎么解决?
NFT ecological development of Ignis public chain: unicorn Donation and development of Art
Positioning of high precision welding manipulator