java 2獲取和設定執行緒名稱

2021-09-05 12:30:58 字數 824 閱讀 1341

string getname():獲取執行緒的名稱。

這個方法是放在寫在自定義執行緒類中的,也即是thread的子類:

public

class

mythread

extends

thread

}}

setname(string name)

方法1:無參構造+set***()

public

class

mythreaddemo1

}

方法2:帶參構造方法給執行緒起名字

public

mythread()

public

mythread

(string name)

mythread my1 =

newmythread

("張三");

mythread my2 =

newmythread

("李四"

);

public static thread currentthread()

public

class

twothreadgetname

extends

thread

}public

void

printmsg()

public

static

void

main

(string[

] args)

}}

取得和設定執行緒的名稱

package getname import j a.util.missingformatargumentexception 寫乙個demo 設定執行緒名稱和獲得當前執行緒的名稱 thread 的方法 string getname 返回該執行緒的名稱。static thread currentthr...

java2 介面和鍊錶 例

寵物商店 介面的使用,類的封裝,鍊錶 inte ce pet abstract class pets implements pet public string getname public string getage public string getcolor class cat extends ...

(一)執行緒管理 2 獲取和設定執行緒資訊

執行緒中包含一些屬性 id 執行緒id name prioity 優先順序,能夠設定1到10 優先順序由低到高 status 執行緒狀態,共有六個 new,runnable,blocked,waiting,time waiting,terminated public class calculator...