当前位置:网站首页>线程的启动与优先级
线程的启动与优先级
2022-07-02 23:33:00 【InfoQ】
start() 和 run() 的区别
public synchronized void start() {
if (threadStatus != 0)
throw new IllegalThreadStateException();
group.add(this);
boolean started = false;
try {
start0();
started = true;
} finally {
try {
if (!started) {
group.threadStartFailed(this);
}
} catch (Throwable ignore) {
// 不处理任何异常,如果 start0 抛出异常,则它将被传递到调用堆栈上
}
}
}
if (threadStatus != 0) throw new IllegalThreadStateException();group.add(this);catch (Throwable ignore) { }public class Thread implements Runnable {
......
private Runnable target;
@Override
public void run() {
if (target != null) {
target.run();
}
}
}
线程的优先级
public final static int MIN_PRIORITY = 1;
public final static int NORM_PRIORITY = 5;
public final static int MAX_PRIORITY = 10
public final void setPriority(int newPriority) {
ThreadGroup g;
checkAccess();
if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) {
throw new IllegalArgumentException();
}
if((g = getThreadGroup()) != null) {
if (newPriority > g.getMaxPriority()) {
newPriority = g.getMaxPriority();
}
setPriority0(priority = newPriority);
}
}
if (newPriority > MAX_PRIORITY || newPriority < MIN_PRIORITY) { } if (newPriority > g.getMaxPriority()) { newPriority = g.getMaxPriority();}边栏推荐
猜你喜欢

UART、RS232、RS485、I2C和SPI的介绍

redis21道经典面试题,极限拉扯面试官

为什么网站打开速度慢?

TypeError: Cannot read properties of undefined (reading ***)

Logback configuration file

多进程编程(一):基本概念

TypeError: Cannot read properties of undefined (reading ***)

Feature Engineering: summary of common feature transformation methods

University of Oslo: Li Meng | deep reinforcement learning based on swing transformer

Where can I find the English literature of the thesis (except HowNet)?
随机推荐
【雅思阅读】王希伟阅读P2(阅读填空)
Is there a specific format for English papers?
What website can you find English literature on?
Go自定义排序
Andorid 获取系统标题栏高度
Install docker and use docker to install MySQL
Bigder: how to deal with the bugs found in the 32/100 test if they are not bugs
有哪些比较推荐的论文翻译软件?
Thinkadmin V6 arbitrary file read vulnerability (cve-2020-25540)
FRP reverse proxy +msf get shell
CMake基本使用
【luogu P4320】道路相遇(圆方树)
AcWing_ 188. Warrior cattle_ bfs
多进程编程(三):消息队列
Hundreds of continuous innovation to create free low code office tools
Linux Software: how to install redis service
Program analysis and Optimization - 9 appendix XLA buffer assignment
Nc20806 District interval
kubernetes编写yml简单入门
Free we media essential tools sharing