public class Threads extends Object
| 限定符和类型 | 类和说明 |
|---|---|
static class |
Threads.NamePredicate
A predicate implementation which matches a thread or threadgroup name.
|
static interface |
Threads.ThreadGroupPredicate
A predicate for selecting threadgroups.
|
static class |
Threads.ThreadIdPredicate
A predicate implementation which matches a thread id.
|
static interface |
Threads.ThreadPredicate
A predicate for selecting threads.
|
| 限定符和类型 | 字段和说明 |
|---|---|
static com.jn.langx.util.concurrent.Threads.AlwaysTruePredicate |
ALWAYS_TRUE_PREDICATE
Predicate which always returns true.
|
| 限定符和类型 | 方法和说明 |
|---|---|
static Thread |
findThreadById(long threadId)
Finds the active thread with the specified id.
|
static Thread |
findThreadById(long threadId,
String threadGroupName)
Finds the active thread with the specified id if it belongs to a thread group with the specified group name.
|
static Thread |
findThreadById(long threadId,
ThreadGroup threadGroup)
Finds the active thread with the specified id if it belongs to the specified thread group.
|
static Collection<ThreadGroup> |
findThreadGroups(ThreadGroup group,
boolean recurse,
Threads.ThreadGroupPredicate predicate)
Select all active threadgroups which match the given predicate and which is a subgroup of the given thread group (or one of its subgroups).
|
static Collection<ThreadGroup> |
findThreadGroups(Threads.ThreadGroupPredicate predicate)
Select all active threadgroups which match the given predicate.
|
static Collection<ThreadGroup> |
findThreadGroupsByName(String threadGroupName)
Finds active thread groups with the specified group name.
|
static Collection<Thread> |
findThreads(ThreadGroup group,
boolean recurse,
Threads.ThreadPredicate predicate)
Select all active threads which match the given predicate and which belongs to the given thread group (or one of its subgroups).
|
static Collection<Thread> |
findThreads(Threads.ThreadPredicate predicate)
Select all active threads which match the given predicate.
|
static Collection<Thread> |
findThreadsByName(String threadName)
Finds active threads with the specified name.
|
static Collection<Thread> |
findThreadsByName(String threadName,
String threadGroupName)
Finds active threads with the specified name if they belong to a thread group with the specified group name.
|
static Collection<Thread> |
findThreadsByName(String threadName,
ThreadGroup threadGroup)
Finds active threads with the specified name if they belong to a specified thread group.
|
static Collection<ThreadGroup> |
getAllThreadGroups()
Gets all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).
|
static Collection<Thread> |
getAllThreads()
Gets all active threads (A thread is active if it has been started and has not yet died).
|
static int |
getAvailableThreadNum(float blockRate)
获取需要创建线程数
线程分工原则:
计算密集型尽量少创建线程,多分段处理; IO密集型尽量多创建线程 |
static ThreadGroup |
getSystemThreadGroup()
Gets the system thread group (sometimes also referred as "root thread group").
|
public static final com.jn.langx.util.concurrent.Threads.AlwaysTruePredicate ALWAYS_TRUE_PREDICATE
public static int getAvailableThreadNum(float blockRate)
线程分工原则:
计算密集型尽量少创建线程,多分段处理;
IO密集型尽量多创建线程
blockRate - 阻塞率,小数,取值范围:[0,1) ,即0到1之间包含0,不包含1public static Thread findThreadById(long threadId, ThreadGroup threadGroup)
threadId - The thread idthreadGroup - The thread groupnull is returned if no such thread existsIllegalArgumentException - if the specified id is zero or negative or the group is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Thread findThreadById(long threadId, String threadGroupName)
threadId - The thread idthreadGroupName - The thread group namenull is returned if no such thread existsIllegalArgumentException - if the specified id is zero or negative or the group name is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<Thread> findThreadsByName(String threadName, ThreadGroup threadGroup)
threadName - The thread namethreadGroup - The thread groupIllegalArgumentException - if the specified thread name or group is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<Thread> findThreadsByName(String threadName, String threadGroupName)
threadName - The thread namethreadGroupName - The thread group nameIllegalArgumentException - if the specified thread name or group name is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<ThreadGroup> findThreadGroupsByName(String threadGroupName)
threadGroupName - The thread group nameIllegalArgumentException - if group name is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<ThreadGroup> getAllThreadGroups()
SecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static ThreadGroup getSystemThreadGroup()
SecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<Thread> getAllThreads()
SecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<Thread> findThreadsByName(String threadName)
threadName - The thread nameIllegalArgumentException - if the specified name is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Thread findThreadById(long threadId)
threadId - The thread idnull if no such thread existsIllegalArgumentException - if the specified id is zero or negativeSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<Thread> findThreads(Threads.ThreadPredicate predicate)
predicate - the predicateCollection of active threads matching the given predicateIllegalArgumentException - if the predicate is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<ThreadGroup> findThreadGroups(Threads.ThreadGroupPredicate predicate)
predicate - the predicateCollection of active threadgroups matching the given predicateIllegalArgumentException - if the predicate is nullSecurityException - if the current thread cannot access the system thread groupSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<Thread> findThreads(ThreadGroup group, boolean recurse, Threads.ThreadPredicate predicate)
group - the thread grouprecurse - if true then evaluate the predicate recursively on all threads in all subgroups of the given grouppredicate - the predicateCollection of active threads which match the given predicate and which belongs to the given thread groupIllegalArgumentException - if the given group or predicate is nullSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static Collection<ThreadGroup> findThreadGroups(ThreadGroup group, boolean recurse, Threads.ThreadGroupPredicate predicate)
group - the thread grouprecurse - if true then evaluate the predicate recursively on all threadgroups in all subgroups of the given grouppredicate - the predicateCollection of active threadgroups which match the given predicate and which is a subgroup of the given thread groupIllegalArgumentException - if the given group or predicate is nullSecurityException - if the current thread cannot modify
thread groups from this thread's thread group up to the system thread groupCopyright © 2022. All rights reserved.