(二十九)Java工具類ThreadUtils詳解
阿新 • • 發佈:2019-02-16
原文連結:https://blog.csdn.net/yaomingyang/article/details/79320387
前言:ThreadUtils是對於java.lang.Thread和java.lang.ThreadGroup的擴充套件和幫助;
1.建構函式
public ThreadUtils() {}
- 1
分析:ThreadUtils 例項不應該在標準的應用程式中構建,相反,這個類應該使用ThreadUtils.getAllThreads(),此建構函式是公開的,允許使用JavaBean例項操作的工具;
2.public static Collection getAllThreads()
分析:返回所有活動執行緒(如果執行緒已經啟動,並且尚未死亡);
3.public static Collection getAllThreadGroups()
分析:返回除系統執行緒組之外的所有活動執行緒組(如果執行緒組未被銷燬,則它是活動的)。
4.public static ThreadGroup getSystemThreadGroup()
分析:返回系統執行緒組(有時也稱為“root thread group”)。
5.public static Collection findThreadsByName(String threadName, ThreadGroup threadGroup)
分析:返回指定執行緒組中指定名字的執行緒;
6.public static Collection findThreadsByName(String threadName,String threadGroupName)
分析:返回指定組名稱執行緒組中指定名稱的執行緒;
7.public static Collection findThreadsByName(String threadName)
分析:返回活動名稱的指定執行緒;
8.public static Collection findThreads(ThreadUtils.ThreadPredicate predicate)
分析:選擇與給定謂詞匹配的所有活動執行緒;
9.public static Collection findThreads(ThreadGroup group,boolean recurse,ThreadUtils.ThreadPredicate predicate)
分析:選擇與給定謂詞匹配的所有活動執行緒,該執行緒屬於給定執行緒組(或其一個子組);
10.public static Collection findThreadGroupsByName(String threadGroupName)
分析:以指定的組名稱返回活動執行緒組;
11.public static Collection findThreadGroups(ThreadUtils.ThreadGroupPredicate predicate)
分析:返回所有與給定謂詞匹配活動的執行緒組;
12.public static Thread findThreadById(long threadId,ThreadGroup threadGroup)
分析:返回屬於指定的執行緒組中指定執行緒ID的執行緒;
13.public static Thread findThreadById(long threadId, String threadGroupName)
分析:返回屬於指定執行緒組名稱的執行緒組中指定執行緒ID的執行緒;
14.public static Thread findThreadById(long threadId)
分析:返回指定執行緒ID的執行緒;