public class ThreadUtils
extends java.lang.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 java.lang.Thread |
findThreadById(long threadId)
Return the active thread with the specified id.
|
static java.lang.Thread |
findThreadById(long threadId,
java.lang.String threadGroupName)
Return the active thread with the specified id if it belongs to a thread group with the specified group name.
|
static java.lang.Thread |
findThreadById(long threadId,
java.lang.ThreadGroup threadGroup)
Return the active thread with the specified id if it belongs to the specified thread group.
|
static java.util.Collection<java.lang.ThreadGroup> |
findThreadGroups(java.lang.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 java.util.Collection<java.lang.ThreadGroup> |
findThreadGroups(ThreadUtils.ThreadGroupPredicate predicate)
Select all active threadgroups which match the given predicate.
|
static java.util.Collection<java.lang.ThreadGroup> |
findThreadGroupsByName(java.lang.String threadGroupName)
Return active thread groups with the specified group name.
|
static java.util.Collection<java.lang.Thread> |
findThreads(java.lang.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 java.util.Collection<java.lang.Thread> |
findThreads(ThreadUtils.ThreadPredicate predicate)
Select all active threads which match the given predicate.
|
static java.util.Collection<java.lang.Thread> |
findThreadsByName(java.lang.String threadName)
Return active threads with the specified name.
|
static java.util.Collection<java.lang.Thread> |
findThreadsByName(java.lang.String threadName,
java.lang.String threadGroupName)
Return active threads with the specified name if they belong to a thread group with the specified group name.
|
static java.util.Collection<java.lang.Thread> |
findThreadsByName(java.lang.String threadName,
java.lang.ThreadGroup threadGroup)
Return active threads with the specified name if they belong to a specified thread group.
|
static java.util.Collection<java.lang.ThreadGroup> |
getAllThreadGroups()
Return all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).
|
static java.util.Collection<java.lang.Thread> |
getAllThreads()
Return all active threads (A thread is active if it has been started and has not yet died).
|
static java.lang.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 java.lang.Thread findThreadById(long threadId, java.lang.ThreadGroup threadGroup)
threadId
- The thread idthreadGroup
- The thread groupnull
is returned if no such thread existsjava.lang.IllegalArgumentException
- if the specified id is zero or negative or the group is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.lang.Thread findThreadById(long threadId, java.lang.String threadGroupName)
threadId
- The thread idthreadGroupName
- The thread group namenull
is returned if no such thread existsjava.lang.IllegalArgumentException
- if the specified id is zero or negative or the group name is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.Thread> findThreadsByName(java.lang.String threadName, java.lang.ThreadGroup threadGroup)
threadName
- The thread namethreadGroup
- The thread groupjava.lang.IllegalArgumentException
- if the specified thread name or group is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.Thread> findThreadsByName(java.lang.String threadName, java.lang.String threadGroupName)
threadName
- The thread namethreadGroupName
- The thread group namejava.lang.IllegalArgumentException
- if the specified thread name or group name is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.ThreadGroup> findThreadGroupsByName(java.lang.String threadGroupName)
threadGroupName
- The thread group namejava.lang.IllegalArgumentException
- if group name is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.ThreadGroup> getAllThreadGroups()
java.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.lang.ThreadGroup getSystemThreadGroup()
java.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.Thread> getAllThreads()
java.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.Thread> findThreadsByName(java.lang.String threadName)
threadName
- The thread namejava.lang.IllegalArgumentException
- if the specified name is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.lang.Thread findThreadById(long threadId)
threadId
- The thread idnull
if no such thread existsjava.lang.IllegalArgumentException
- if the specified id is zero or negativejava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.Thread> findThreads(ThreadUtils.ThreadPredicate predicate)
predicate
- the predicateCollection
of active threads matching the given predicatejava.lang.IllegalArgumentException
- if the predicate is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.ThreadGroup> findThreadGroups(ThreadUtils.ThreadGroupPredicate predicate)
predicate
- the predicateCollection
of active threadgroups matching the given predicatejava.lang.IllegalArgumentException
- if the predicate is nulljava.lang.SecurityException
- if the current thread cannot access the system thread groupjava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.Thread> findThreads(java.lang.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 groupjava.lang.IllegalArgumentException
- if the given group or predicate is nulljava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread grouppublic static java.util.Collection<java.lang.ThreadGroup> findThreadGroups(java.lang.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 groupjava.lang.IllegalArgumentException
- if the given group or predicate is nulljava.lang.SecurityException
- if the current thread cannot modify
thread groups from this thread's thread group up to the system thread group"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"