建立執行緒物件的三種方式

2021-07-15 00:24:09 字數 402 閱讀 5691

建立執行緒物件的三種方式

1、自定義類繼承thread類,重寫run方法。

public class rabbit extends thread 

}}

2、自定義類實現runnable介面,重寫run方法。使用靜態**建立thread 物件,啟動執行緒。

public class programmer implements runnable 	}}

3、生成乙個匿名類,並重寫run方法。

thread t1 = new thread(new runnable() 

}});

以上為常用的建立執行緒的方式,歡迎補充。

執行緒 三種方式 建立執行緒

第一種 1 模擬龜兔賽跑 繼承thread 重寫run 執行緒體 2 使用執行緒 建立子類物件 物件.strat 執行緒啟動 author administrator public class rabbits extends thread class tortoise extends thread ...

執行緒的三種建立方式

public class web12306 多執行緒的三種方式 class threadtest01 extends thread class threadtest02 implements runnable class threadtest03 implements callable return...

建立執行緒的三種方式

一 是繼承thread方法 public class mythread extends thread private void dosomething public class newthread private static void dosomething 二 是實現runnable介面 使用r...