public class ThreadUtils extends Object
Helpers for java.lang.Thread
and java.lang.ThreadGroup
.
#ThreadSafe#
Thread
,
ThreadGroup
Modifier and Type | Class and Description |
---|---|
static class |
ThreadUtils.NamePredicate
A predicate implementation which matches a thread or threadgroup name.
|
static interface |
ThreadUtils.ThreadGroupPredicate
A predicate for selecting threadgroups.
|
static class |
ThreadUtils.ThreadIdPredicate
A predicate implementation which matches a thread id.
|
static interface |
ThreadUtils.ThreadPredicate
A predicate for selecting threads.
|
Modifier and Type | Field and Description |
---|---|
static org.apache.commons.lang3.ThreadUtils.AlwaysTruePredicate |
ALWAYS_TRUE_PREDICATE
Predicate which always returns true.
|
Constructor and Description |
---|
ThreadUtils()
ThreadUtils instances should NOT be constructed in standard programming.
|
Modifier and Type | Method and Description |
---|---|
static Thread |
findThreadById(long threadId)
Return the active thread with the specified id.
|
static Thread |
findThreadById(long threadId,
String threadGroupName)
Return 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)
Return the active thread with the specified id if it belongs to the specified thread group.
|
static Collection<ThreadGroup> |
findThreadGroups(ThreadGroup group,
boolean recurse,
ThreadUtils.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(ThreadUtils.ThreadGroupPredicate predicate)
Select all active threadgroups which match the given predicate.
|
static Collection<ThreadGroup> |
findThreadGroupsByName(String threadGroupName)
Return active thread groups with the specified group name.
|
static Collection<Thread> |
findThreads(ThreadGroup group,
boolean recurse,
ThreadUtils.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(ThreadUtils.ThreadPredicate predicate)
Select all active threads which match the given predicate.
|
static Collection<Thread> |
findThreadsByName(String threadName)
Return active threads with the specified name.
|
static Collection<Thread> |
findThreadsByName(String threadName,
String threadGroupName)
Return 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)
Return active threads with the specified name if they belong to a specified thread group.
|
static Collection<ThreadGroup> |
getAllThreadGroups()
Return all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).
|
static Collection<Thread> |
getAllThreads()
Return all active threads (A thread is active if it has been started and has not yet died).
|
static ThreadGroup |
getSystemThreadGroup()
Return the system thread group (sometimes also referred as "root thread group").
|
public static final org.apache.commons.lang3.ThreadUtils.AlwaysTruePredicate ALWAYS_TRUE_PREDICATE
public ThreadUtils()
ThreadUtils instances should NOT be constructed in standard programming. Instead, the class should be used as
ThreadUtils.getAllThreads()
This constructor is public to permit tools that require a JavaBean instance to operate.
public 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(ThreadUtils.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(ThreadUtils.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, ThreadUtils.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, ThreadUtils.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 © 2001–2019 The Apache Software Foundation. All rights reserved.