当前位置:网站首页>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());
}
}
边栏推荐
- uniapp 自定义环境变量
- 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
- MySQL information_ Schema database
- JS execution mechanism
- FRP intranet penetration, reverse proxy
- C语言练习题(递归)
- Nexus 6p从8.0降级6.0+root
- C實現貪吃蛇小遊戲
- 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?
- Tsinghua University product: penalty gradient norm improves generalization of deep learning model
猜你喜欢
SQL injection SQL lab 11~22
R statistical mapping - random forest classification analysis and species abundance difference test combination diagram
Impact relay jc-7/11/dc110v
Tree DP
A little understanding of GSLB (global server load balance) technology
198. House raiding
Notes and notes
雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)
17-18. Dependency scope and life cycle plug-ins
测试岗的中年危机该如何选择?是坚守还是另寻出路?且看下文
随机推荐
Compound nonlinear feedback control (2)
Tf/pytorch/cafe-cv/nlp/ audio - practical demonstration of full ecosystem CPU deployment - Intel openvino tool suite course summary (Part 2)
树形dp
MySQL information_ Schema database
740. Delete and get points
Grounding relay dd-1/60
云原生——上云必读之SSH篇(常用于远程登录云服务器)
198. House raiding
Average two numbers
[openvino+paddle] paddle detection / OCR / SEG export based on paddle2onnx
4G wireless all network solar hydrological equipment power monitoring system bms110
Lightroom import picture gray / Black rectangular multi display
webrtc 快速搭建 视频通话 视频会议
手动对list进行分页(参数list ,当前页,页面大小)
实用的小工具指令
The sorting in C language realizes the number sorting method from small to large
8. Factory method
Inputstream/outputstream (input and output of file)
AWT常用组件、FileDialog文件选择框
Weekly summary (*63): about positive energy