当前位置:网站首页>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());
}
}
边栏推荐
- LayoutManager布局管理器:FlowLayout、BorderLayout、GridLayout、GridBagLayout、CardLayout、BoxLayout
- JS get the attribute values nested in the object
- HMS v1.0 appointment. PHP editid parameter SQL injection vulnerability (cve-2022-25491)
- Learning multi-level structural information for small organ segmentation
- Is the insurance annuity product worth buying? Is there a hole?
- Sword finger offer II 038 Daily temperature
- 17-18. Dependency scope and life cycle plug-ins
- Appium foundation - appium installation (II)
- Sort list tool class, which can sort strings
- Gridview出现滚动条,组件冲突,如何解决
猜你喜欢

ES6 模块化

webrtc 快速搭建 视频通话 视频会议

复合非线性反馈控制(二)

Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout

C realize Snake games
![[March 3, 2019] MAC starts redis](/img/ff/88638fcdc8d24dc268781c224e8195.jpg)
[March 3, 2019] MAC starts redis

Abap:ooalv realizes the function of adding, deleting, modifying and checking

The solution of win11 taskbar right click without Task Manager - add win11 taskbar right click function

Json Web token - jwt vs. Traditional session login Authentication

How to realize multi account login of video platform members
随机推荐
Gridview出现滚动条,组件冲突,如何解决
分布式CAP理论
体验碎周报第 102 期(2022.7.4)
2022.7.2-----leetcode. eight hundred and seventy-one
Qt发布多语言国际化翻译
复合非线性反馈控制(二)
MySQL的information_schema数据库
Json Web token - jwt vs. Traditional session login Authentication
How to choose the middle-aged crisis of the testing post? Stick to it or find another way out? See below
Layoutmanager layout manager: flowlayout, borderlayout, GridLayout, gridbaglayout, CardLayout, BoxLayout
微信小程序使用rich-text中图片宽度超出问题
Internet of things protocol ZigBee ZigBee module uses the concept of protocol stack
The solution of win11 taskbar right click without Task Manager - add win11 taskbar right click function
实用的小工具指令
Detectron: train your own data set -- convert your own data format to coco format
Webrtc quickly set up video call and video conference
gslb(global server load balance)技术的一点理解
How to avoid JVM memory leakage?
Compound nonlinear feedback control (2)
雲原生——上雲必讀之SSH篇(常用於遠程登錄雲服務器)