java - java中调用thread.start()后的语句流程是什么?
问题描述
在 thread.start() 之后执行什么语句。主线程的语句或子线程的语句。
线程通常并行运行,但在这种情况下,主线程的语句始终优先于子线程的语句。真正的原因或流程是什么?
public class Test extends Thread {
public static void main(String[] args) {
ChildThread ct = new ChildThread();
ct.start();
System.out.println("main");
}
}
class ChildThread extends Thread{
@Override public void run() {
System.out.println("Child thread");
}
}
解决方案
没有确定的答案是什么语句在 thread.start() 之后执行,但在大多数情况下它将是主线程,因为当你启动新线程时,你的操作系统需要初始化这个线程,而主线程已经在飞。
推荐阅读
- javascript - 如何接收输入 21122001 作为 dmyyyy?我只能输入 21122001 作为格式 ddmmyyyy
- excel - 代码需要超过 10 分钟才能执行
- python-3.x - 如何在 python 曲线拟合中有效地使用“LMFIT”来拟合阻尼余弦波
- azureservicebus - 如何使用标准 Azure 逻辑应用的无状态工作流可靠地处理 Azure 服务总线消息
- python - “运行时错误:未安装默认上下文。”使用 Tensorflow Federated 时
- go - 使文件不可变 - syscall.Chflags("filename", ?)
- python - 将列中的拆分字符串矢量化为多列 pandas
- javascript - 可以使用 useReducer 重新创建类组件状态行为吗?
- python - 输入类型不支持 ufunc 'isnan'
- node.js - 开玩笑 - 测试成功,即使它不应该成功