2014-03-31 28 views
0

嗨,我是一個新手java程序員對線程。而我卡在這個簡單的Java程序簡單的線程程序不起作用

public class Multi extends Thread{ 
    public void run() { 
     try{ 
      System.out.println("running..."); 
     } 
     catch(Exception e){ 
      System.out.print(e); 
     } 
    } 
    public static void main(String[] args){ 
     Multi t1=new Multi(); 
     t1.run();//fine, but does not start a separate call stack 
    } 
} 
+1

答案已經作出,買我必須承認,有大約這麼多,在這麼短的代碼 –

回答

2

線程使用start方法啓動。調用t1.run()方法只是在同一個線程內同步執行run方法。

t1.start(); 

閱讀:Defining and Starting a Thread

+0

搞砸了一些有趣的還是它讓我看到這個種類錯誤「無法找到主要類:多。」 – Parth

+0

如何運行應用程序? – Reimeus

+0

通過命令提示符 – Parth

0
t1.run();// just calls the run method (like any other method) in the same thread. 

use t1.start() // starts a new thread. 
1

的Java線程通過以下方法觸發:

t1.start() // This starts a new thread 

雖然以下:

t1.run();// This calls the run method in the same thread