当前位置:网站首页>线程的调度、线程的优先级
线程的调度、线程的优先级
2022-06-09 06:55:00 【小码哥呀】
1、线程的调度

2、线程的优先级

/** * 1、线程的优先级 * MAX_PRIORITY:10 * MIN_PRIORITY:1 * NORM_PRIORITY:5 * 2、如何获取和设置当前线程的优先级 * getPriority():获取线程的优先级 * setPriority():设置线程的优先级 * * 说明:高优先级的现线程要抢占低优先级cpu的执行权,但是只是从概率上讲,高优先级的线程高概率的情况下被执行。 * 并以意味着只有当高优先级的线程执行完以后,低优先级的线程才执行。 * * DATE: 2022/6/5 22:35 */
class HelloThread2 extends Thread{
@Override
public void run() {
for(int i = 0;i < 100;i++) {
if (i % 2 == 0) {
System.out.println(Thread.currentThread().getName() + ":"+Thread.currentThread().getPriority()+":"+ i);
}
}
}
}
public class ThreadPriority {
public static void main(String[] args) {
HelloThread2 h2 = new HelloThread2();
//给当前线程设置名字
h2.setName("线程h2");
//设置分线程的优先级
h2.setPriority(Thread.MAX_PRIORITY);
h2.start();
Thread.currentThread().setName("主线程");
//设置主线程的优先级
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
for(int i = 0;i < 100;i++) {
if (i % 2 == 0) {
System.out.println(Thread.currentThread().getName() + ":" +Thread.currentThread().getPriority()+":"+ i);
}
}
}
}
边栏推荐
- After ppt imports video clipping, how to save the clipped video as?
- 5. Multimedia Foundation
- InfoWorld文章丨将数据编排技术用于AI模型训练
- Jump from one pit to another
- UML series articles (26) architecture modeling -- artifacts
- MySQL chapter of quantitative transactions - addition, deletion, modification and query of MySQL database
- Quit smoking log_ 01 (day_02)
- UML系列文章(19)基本行为---交互图
- MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
- 批量写入tidb提高写入效率
猜你喜欢

批量写入tidb提高写入效率

UML系列文章(20)基本行为---活动图

若依 思维导图

WPF 数据绑定(二)

Matlab: tf2zp与tf2zpk的差异

Database final exam outline

当内卷风波及代码领域,看Alluxio将会采取怎样的块分配策略

Champignon Street publie les résultats de l'exercice 2022: les pertes du deuxième semestre ont diminué de 50% d'une année sur l'autre

Chapter_ 06 changing the contrast and brightness of an image

pycharm 和mysql做学生信息管理系统问题求解
随机推荐
Database final exam outline
For an experienced software engineer, what would be a preferred new programming language to learn?
新职业:数字化管理师太抢手,只要来面试,企业就会发offer
100 code structure and how to avoid them (4)
257. 二叉树的所有路径
【系统分析师之路】第十八章 复盘系统安全分析与设计(加密与解密)
parker液压马达要注意哪些问题?
纯英式 VoxEdit 大赛来啦
ROS编译报错 genmsg/cmake/genmsg-extras.cmake:307 的解决方法
使用postman模拟携带token的请求
How to select Bucher hydraulic pump? It is important to master these three points!
Idea如何查看保存代码的路径
android导入sqllite数据库
QT console project display label small window
[SDU project training level 2019] router link: who will execute to or @click first
The Sandbox 和 Ikonia 达成合作,在元宇宙中还原足球传奇人物皮尔洛的壁画
PPT导入视频裁剪后,如何裁剪后的视频另存为保存下来?
Defi demirisk: analyse des risques systémiques dans les systèmes décentralisés
数学很差能学机器学习吗?
类和对象初阶