多執行緒學習

2021-08-26 16:46:59 字數 495 閱讀 6381

簡單學習多執行緒。

建立多執行緒有兩種方法。

一:繼承thread類。

/**

* 多執行緒練習,通過繼承thread

* */

public class testthread extends thread

public static void main(string argsd)

}

二:實現runnable介面。

/**

* 多執行緒練習。通過實現runnable介面。

* */

public class testthread2 implements runnable

@override

public void run()

}

thread類也是繼承了runnable介面。 runnable介面只定義了run 方法。

啟動多執行緒使用 start 方法。

多執行緒學習

thread和runnable的區別 單繼承模式thread 而 runnable是介面 start 和run的區別 start是乙個執行緒只能啟動,run可以執行多次,並且run是呼叫當前正在執行的執行緒 wait notify object物件所具有的 sleep setpriority 同步機...

多執行緒學習

用 編輯 的多執行緒時用gcc threadtest 1.c 編譯時 一直報錯,報錯如下 tmp ccgko5iu.o 在函式 thread create 中 threadtest 1.c text 0x13b 對 pthread create 未定義的引用 threadtest 1.c text ...

多執行緒學習

用 編輯 的多執行緒時用gcc threadtest 1.c 編譯時 一直報錯,報錯如下 tmp ccgko5iu.o 在函式 thread create 中 threadtest 1.c text 0x13b 對 pthread create 未定義的引用 threadtest 1.c text ...