当前位置:网站首页>7.线程优先级
7.线程优先级
2022-08-08 06:23:00 【永远的攀登者】
7.线程优先级
所谓的优先级是越高的优先级,越有可能先执行。在Thread里面提供如下方法:
- 设置优先级:public final void setPriority(int newPriority)
- 取得优先级:public final int getPriority()
发现设置和取得优先级都是使用int数据类型,对此有三种取值:
- 最高优先级:public final static int MAX_PRIORITY = 10;
- 中等优先级:public final static int NORM_PRIORITY = 5;
- 最低优先级:public final static int MIN_PRIORITY = 1;
代码如下:
public class TestSleep implements Runnable{
@Override
public void run() {
for(int i=0;i<10;i++){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.print("购物,mony = " + Thread.currentThread().getName());
}
}
}
class MySleep{
public static void main(String[] args) {
TestSleep testSleep = new TestSleep();
Thread t1 = new Thread(testSleep,"A");
Thread t2 = new Thread(testSleep,"B");
Thread t3 = new Thread(testSleep,"C");
t1.setPriority(Thread.MAX_PRIORITY);
t1.start();
t2.start();
t3.start();
}
}
注意:设置优先级可能先执行,不是必须的
边栏推荐
猜你喜欢

2022年中国儿童食品市场规模与发展趋势

Plant spice market research: China's market development status and business model analysis in 2022

Scrapy爬虫框架详解-----全面详解

C语言三子棋游戏进阶版详解(包括多子棋)
![[BSidesCF 2020] Had a bad day1](/img/18/872d1c4a87608c618d2add0a65c4ba.png)
[BSidesCF 2020] Had a bad day1

Shell(二)

Consumer Goods Industry Report: Coconut Oil Market Status Research Analysis and Development Prospect Forecast

cengBox靶机wp

Scrapy_Redis 分布式处理

2021年度总结
随机推荐
节流与防抖
Anaconda installation and use
简要概述深度学习和机器学期的区别
Redis集群
[GWCTF 2019]我有一个数据库1
plt.axis(‘tight‘) 的含义
EOF指令在C语言中的作用
COSMIC: COmmonSense knowledge for eMotion Identification in Conversations
爬取实习吧前四页的招聘信息
课堂作业--整数转字符串
2022年中国儿童食品市场规模与发展趋势
5个网络问题,了解网络协议栈的哪些不为人知的八股文(来波千人福利)
2022年天然橡胶市场供需与价格走势
YoloV4训练自己的数据集(四)
数组拼接时维度的重要性
机器学习,信用卡项目(二分类问题)完整代码 + 详细注释
Anaconda安装使用
图像评价方法程序-PSNR
总结:numpy常用方法
化工材料行业报告-己二酸市场现状研究分析与发展前景预测