多執行緒的使用

2022-06-08 12:33:11 字數 395 閱讀 6232

多執行緒中使用runnable的介面與thread類來實現,注意是thread類不是其子類,關鍵是將runnable介面作為引數進行傳遞

另外兩個共同的類作為執行緒則成員變數是共享的。。。。指的是run以外的

thread.currentthread()返回執行緒編號

thread.currentthread().getname()返回設定的名字

第乙個類

public class process

}第二個類

class user implements runnable

public void run()

if(name.equals("貓"))

trycatch(interruptedexception e)}}

}

多執行緒的使用

建立子執行緒的幾種方式 第一種方式 使用執行緒類 nsthread nsthread detachnewthreadselector selector task1 totarget self withobject nil 第二種方式 使用執行緒類,需要手動開啟子執行緒 nsthread thread...

多執行緒的使用

using system using system.threading namespace 15.1thread 正在執行測試方法 thread.currentthread.name static void main string args 乙個可能的情況,因為多執行緒是並行的,不能確定每一次具體的...

多執行緒的使用

package cm.aichijihua public class threadtest1 catch interruptedexception e system.out.println thread.currentthread getname system.out.println this.ge...