什么语句在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() 之后执行什么语句,但在大多数情况下它将是主线程,因为当您启动新线程时,您的操作系统需要初始化该线程,而主线程是已经在运行了。
关于java - java中调用thread.start()后的语句流程是怎样的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56088182/