当前位置:网站首页>thread priority
thread priority
2022-07-04 06:29:00 【Hao Kai】
Thread priority
Java A thread scheduler is provided to monitor all threads in the program that enter ready state after startup , The thread scheduler determines which thread should be scheduled to execute according to the priority
The priority of a thread is represented by a number , Range from 1~10
- Thread.MIN_PRIORITY=1
- Thread.MAX_PRIORITY=10
- Thread.NORM_PRIORITY=5
Use the following methods to obtain and change the priority of threads
- getPriority()
- setPriority(int xxx)
High priority means grabbing CPU The probability of time slice is high , It doesn't have to be done first , We set priorities , For reference only , Unable to determine the final execution order of threads
package com.example.demo.testthread;
public class TestPriority implements Runnable {
public static void main(String[] args) {
TestPriority testPriority = new TestPriority();
Thread t1 = new Thread(testPriority, " Threads 1");
t1.start();
Thread t2 = new Thread(testPriority, " Threads 2");
t2.setPriority(Thread.MIN_PRIORITY);
t2.start();
Thread t3 = new Thread(testPriority, " Threads 3");
t3.setPriority(Thread.MAX_PRIORITY);
t3.start();
Thread t4 = new Thread(testPriority, " Threads 4");
t4.setPriority(8);
t4.start();
Thread t5 = new Thread(testPriority, " Threads 5");
t5.setPriority(Thread.NORM_PRIORITY);
t5.start();
System.out.println(Thread.currentThread().getName()+" perform , The weight of "+Thread.currentThread().getPriority());
/* High priority means grabbing CPU The probability of time slice is high , It doesn't have to be done first , We set priorities , For reference only , Unable to determine the final execution order of threads Output : Threads 3 perform , The weight of 10 main perform , The weight of 5 Threads 1 perform , The weight of 5 Threads 4 perform , The weight of 8 Threads 5 perform , The weight of 5 Threads 2 perform , The weight of 1 */
}
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+" perform , The weight of "+Thread.currentThread().getPriority());
}
}
边栏推荐
- Operator < <> > fool test case
- 11. Dimitt's law
- ORICO ORICO outdoor power experience, lightweight and portable, the most convenient office charging station
- Detailed explanation of common APIs for component and container containers: frame, panel, scrollpane
- Which water in the environment needs water quality monitoring
- Gridview出现滚动条,组件冲突,如何解决
- 运算符<< >>傻瓜式测试用例
- AWT常用组件、FileDialog文件选择框
- Nexus 6p从8.0降级6.0+root
- Error CVC complex type 2.4. a: Invalid content beginning with element 'base extension' was found. Should start with one of '{layoutlib}'.
猜你喜欢

云原生——上云必读之SSH篇(常用于远程登录云服务器)

如何实现视频平台会员多账号登录

Overview of convolutional neural network structure optimization

QT QTableWidget 表格列置顶需求的思路和代码

Webrtc quickly set up video call and video conference

Inputstream/outputstream (input and output of file)

what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!

MySQL learning notes 3 - JDBC

webrtc 快速搭建 视频通话 视频会议
![Yiwen unlocks Huawei's new cloud skills - the whole process of aiot development [device access - ESP end-to-side data collection [mqtt]- real time data analysis] (step-by-step screenshot is more detai](/img/a5/be967170a18cb2de097f01a6d4e039.jpg)
Yiwen unlocks Huawei's new cloud skills - the whole process of aiot development [device access - ESP end-to-side data collection [mqtt]- real time data analysis] (step-by-step screenshot is more detai
随机推荐
lightroom 导入图片灰色/黑色矩形 多显示器
Understanding of cross domain and how to solve cross domain problems
1、 Relevant theories and tools of network security penetration testing
Experience weekly report no. 102 (July 4, 2022)
Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
Another company raised the price of SAIC Roewe new energy products from March 1
注释与注解
Learn about the Internet of things protocol WiFi ZigBee Bluetooth, etc. --- WiFi and WiFi protocols start from WiFi. What do we need to know about WiFi protocol itself?
【无标题】
Distributed cap theory
AWT常用组件、FileDialog文件选择框
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
运算符<< >>傻瓜式测试用例
分布式CAP理论
How to choose the middle-aged crisis of the testing post? Stick to it or find another way out? See below
Tree DP
Invalid bound statement (not found): com. example. mapper. TblUserRecordMapper. login
High performance parallel programming and optimization | lesson 02 homework at home
Invalid revision: 3.18.1-g262b901-dirty
C realize Snake games