当前位置:网站首页>线程的启动与优先级
线程的启动与优先级
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();}
边栏推荐
- NC50965 Largest Rectangle in a Histogram
- Hundreds of continuous innovation to create free low code office tools
- Seckill system design
- Centos7 one click compilation to build MySQL script
- Introduction and use of ftrace tool
- Form form instantiation
- Detailed explanation of pod life cycle
- 如何系统学习机器学习
- Free we media essential tools sharing
- UART、RS232、RS485、I2C和SPI的介绍
猜你喜欢
字符设备注册常用的两种方法和步骤
setInterval定时器在ie不生效原因之一:回调的是箭头函数
Luogu_ P1149 [noip2008 improvement group] matchstick equation_ Enumeration and tabulation
Introduction and use of ftrace tool
Basic 10 of C language: array and pointer
Shell implements basic file operations (cutting, sorting, and de duplication)
可下载《2022年中国数字化办公市场研究报告》详解1768亿元市场
[shutter] Introduction to the official example of shutter Gallery (project introduction | engineering construction)
百数不断创新,打造自由的低代码办公工具
Why is the website slow to open?
随机推荐
[Luogu p4320] road meets (round square tree)
Andorid gets the system title bar height
antv x6节点拖拽到画布上后的回调事件(踩大坑记录)
Free we media essential tools sharing
TypeError: Cannot read properties of undefined (reading ***)
LeedCode1480.一维数组的动态和
Implement the foreach method of array
Pytorch 20 realizes corrosion expansion based on pytorch
多进程编程(四):共享内存
logback配置文件
简单聊聊运维监控的其他用途
【雅思阅读】王希伟阅读P2(阅读填空)
Mutual exclusion and synchronization of threads
ftrace工具的介绍及使用
An excellent orm in dotnet circle -- FreeSQL
Form form instantiation
Helm basic learning
【雅思阅读】王希伟阅读P1(阅读判断题)
论文的英文文献在哪找(除了知网)?
Multiprocess programming (4): shared memory