【发布时间】:2019-12-07 13:44:41
【问题描述】:
class test1 extends Thread
{
public void run()
{
System.out.println("Run method executed by child Thread");
}
public static void main(String[] args)
{
test1 t = new test1();
t.start();
System.out.println(726*656);
System.out.println("Main method executed by main thread");
}
}
输出是 -
476256
Main method executed by main thread
Run method executed by child Thread
为什么即使我先调用 start 方法,线程语句也会最后出现
【问题讨论】:
-
它不会总是生成相同的输出,因为
Thread不保证它。尝试多次运行程序,输出会改变 -
如果你想要顺序输出,那么使用两个线程是没有意义的。在这种情况下,只需在主线程上执行所有操作。
标签: java multithreading