class test{
public static void main(String[] str){
NewThread t = new NewThread();
System.out.println("Main Thread");
}
}//end of class test

class NewThread{
Thread t;
public NewTrhead(){
t = new Thread();
t.star();
}
void run(){
print("child thread");
}
}//end of class NewThread==========================
为什么main thread先于child thread被打印出来?

解决方案 »

  1.   

    main 又没有sleep 当然自己继续往下执行了。。
      

  2.   

    程序运行时,main线程启动,main线程运行时才启动child线程,main当然先于child先完成了
      

  3.   

    t = new Thread();
    t.start();
    t.join();这样就好了
      

  4.   

    程序运行时,main线程启动,main线程运行时才启动child线程,main当然先于child先完成了 ?
    错了吧!!!根本不是这原因  这跟线程的调度有关系。。
     
      

  5.   

    类运行先找main()方法,然后通过main()调度其他的线程
      

  6.   

    这个先运行main函数,然后创建一个新对象,那个新对象的线程就在一个新线程里面运行了,这样main函数的线程跟新线程就是并行运行,并行运行的时候,不能100%的保证一定System.out.println("Main Thread");要比print("child thread");早,只能说早的可能性大,因为新线程跑起来要比System.out.println("Main Thread")多跑几条程序才执行print("child thread"),所以看着maintread要早,不过线程调度由系统调度执行,也说不准哪个线程先跑啦,也有可能child先比main打印。