(二十九)Java工具类ThreadUtils详解

原文链接: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的线程;


猜你喜欢

转载自blog.csdn.net/jarniyy/article/details/80446685