我运行了这段代码并得到了以下结果:
//back in main
//directly from the runnable
//top of the stack
我不应该将
top of the stack
作为我的第一个结果吗?public class MyRunnable implements Runnable {
public void run() {
System.out.println("directly from the runnable");
go();
}
public void go() {
doMore();
}
public void doMore() {
System.out.println("top of the stack");
}
}
public class ThreadTester{
public static void main(String[] args) {
Runnable threadJob = new MyRunnable();
Thread myThread = new Thread(threadJob);
myThread.start();
System.out.println("back in main");
}
}
最佳答案
线程没有特定的顺序,可以是任何一种方式。 JVM是决定这一点的,它每次都能给出不同的结果。