当前位置:网站首页>线程的启动与优先级
线程的启动与优先级
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();}边栏推荐
- [Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
- NC24840 [USACO 2009 Mar S]Look Up
- Redis21 classic interview questions, extreme pull interviewer
- 2022上半年值得被看见的10条文案,每一句都能带给你力量!
- One of the reasons why setinterval timer does not take effect in ie: the callback is the arrow function
- Seckill system design
- MySQL 23 classic interview hanging interviewer
- Briefly talk about other uses of operation and maintenance monitoring
- Nc20806 District interval
- University of Toronto:Anthony Coache | 深度强化学习的条件可诱导动态风险度量
猜你喜欢

Mutual exclusion and synchronization of threads

Shell脚本基本使用

Install docker and use docker to install MySQL

Multiprocess programming (I): basic concepts

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

MySQL 23 classic interview hanging interviewer

Bloom filter

pod生命周期详解

使用jenkins之二Job

Logback configuration file
随机推荐
Cmake basic use
Hundreds of continuous innovation to create free low code office tools
Nc20806 District interval
使用jenkins之二Job
论文的英文文献在哪找(除了知网)?
[golang syntax] map common errors golang panic: assignment to entry in nil map
helm 基础学习
Gan model architecture in mm
How to write the design scheme of the thesis?
Markdown使用教程
【Pulsar文档】概念和架构/Concepts and Architecture
mm中的GAN模型架构
Markdown tutorial
logback配置文件
经济学外文文献在哪查?
关于Unity屏幕相关Screen的练习题目,Unity内部环绕某点做运动
Andorid gets the system title bar height
Multiprocess programming (II): Pipeline
Preview word documents online
微信小程序获取某个元素的信息(高、宽等),并将px转换为rpx。