当前位置:网站首页>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());
}
}
边栏推荐
- ES6 modularization
- QT get random color value and set label background color code
- Is the insurance annuity product worth buying? Is there a hole?
- Learning multi-level structural information for small organ segmentation
- 24 magicaccessorimpl can access the debugging of all methods
- Option (024) - do all objects have prototypes?
- 对List进行排序工具类,可以对字符串排序
- JSON web token -- comparison between JWT and traditional session login authentication
- How does apscheduler set tasks not to be concurrent (that is, execute the next task after the first one)?
- Design and implementation of redis 7.0 multi part AOF
猜你喜欢
Json Web token - jwt vs. Traditional session login Authentication
Download kicad on Alibaba cloud image station
Detailed explanation of common APIs for component and container containers: frame, panel, scrollpane
Native Cloud - SSH articles must be read on Cloud (used for Remote Login to Cloud Server)
[openvino+paddle] paddle detection / OCR / SEG export based on paddle2onnx
Win10 clear quick access - leave no trace
A little understanding of GSLB (global server load balance) technology
High performance parallel programming and optimization | lesson 02 homework at home
C语言练习题(递归)
Arcpy uses the updatelayer function to change the symbol system of the layer
随机推荐
对List进行排序工具类,可以对字符串排序
Uninstall Google drive hard drive - you must exit the program to uninstall
金盾视频播放器拦截的软件关键词和进程信息
C语言中的函数(详解)
QT qtablewidget table column top requirements ideas and codes
测试岗的中年危机该如何选择?是坚守还是另寻出路?且看下文
QT 获取随机颜色值设置label背景色 代码
[Android reverse] function interception (CPU cache mechanism | CPU cache mechanism causes function interception failure)
微信小程序使用rich-text中图片宽度超出问题
分布式CAP理论
740. Delete and get points
Component、Container容器常用API详解:Frame、Panel、ScrollPane
ORICO ORICO outdoor power experience, lightweight and portable, the most convenient office charging station
4G wireless all network solar hydrological equipment power monitoring system bms110
C # symmetric encryption (AES encryption) ciphertext results generated each time, different ideas, code sharing
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
云原生——上云必读之SSH篇(常用于远程登录云服务器)
Bicolor case
746. Climb stairs with minimum cost
Reading notes of Clickhouse principle analysis and Application Practice (4)