即使我先将调用先启动,为什么线程最后执行?

问题描述 投票:-6回答:1
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

为什么线程语句最后出现,即使我先调用启动方法也是如此

java multithreading basic
1个回答
1
投票

当您调用start时,新线程开始执行,但是不会影响已经在执行的Main线程。如果希望主线程等待新线程,则可以在新线程上调用“ join”之类的方法以等待其完成

© www.soinside.com 2019 - 2024. All rights reserved.