当前位置:网站首页>线程的启动与优先级
线程的启动与优先级
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();}边栏推荐
- Rust字符串切片、结构体和枚举类
- Question e: merged fruit -noip2004tgt2
- Detailed explanation of pod life cycle
- Where can I find the English literature of the thesis (except HowNet)?
- Implement the foreach method of array
- Briefly talk about other uses of operation and maintenance monitoring
- 写论文可以去哪些网站搜索参考文献?
- Monitor container runtime tool Falco
- Mutual exclusion and synchronization of threads
- 论文的设计方案咋写?
猜你喜欢

如何系统学习机器学习

pod生命周期详解

Should you study kubernetes?

CMake基本使用

How SQLSEVER removes data with duplicate IDS

The "2022 China Digital Office Market Research Report" can be downloaded to explain the 176.8 billion yuan market in detail

setInterval定时器在ie不生效原因之一:回调的是箭头函数

【单片机项目实训】八路抢答器

Basic 10 of C language: array and pointer

多进程编程(二):管道
随机推荐
There is an unknown problem in inserting data into the database
Centos7 one click compilation to build MySQL script
论文的英文文献在哪找(除了知网)?
多进程编程(三):消息队列
Two common methods and steps of character device registration
Shell implements basic file operations (cutting, sorting, and de duplication)
Form form instantiation
Markdown使用教程
【JetCache】JetCache的配置说明和注解属性说明
关于Unity屏幕相关Screen的练习题目,Unity内部环绕某点做运动
FRP reverse proxy +msf get shell
JSON conversion tool class
Question e: merged fruit -noip2004tgt2
pod生命周期详解
Go自定义排序
Go custom sort
Wechat applet obtains the information of an element (height, width, etc.) and converts PX to rpx.
【luogu P4320】道路相遇(圆方树)
Shell implements basic file operations (SED edit, awk match)
Andorid 获取系统标题栏高度