Class ThreadUtils
java.lang.Object
edu.internet2.middleware.grouperClientExt.org.apache.commons.lang3.ThreadUtils
Helpers for java.lang.Thread
and java.lang.ThreadGroup
.
#ThreadSafe#
- Since:
- 3.5
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A predicate implementation which matches a thread or threadgroup name.static interface
A predicate for selecting threadgroups.static class
A predicate implementation which matches a thread id.static interface
A predicate for selecting threads. -
Field Summary
Modifier and TypeFieldDescriptionstatic final edu.internet2.middleware.grouperClientExt.org.apache.commons.lang3.ThreadUtils.AlwaysTruePredicate
Predicate which always returns true. -
Constructor Summary
ConstructorDescriptionThreadUtils instances should NOT be constructed in standard programming. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
(ThreadUtils.ThreadGroupPredicate predicate) Select all active threadgroups which match the given predicate.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>
findThreadGroupsByName
(String threadGroupName) Finds active thread groups with the specified group name.static Collection<Thread>
findThreads
(ThreadUtils.ThreadPredicate predicate) Select all active threads which match the given predicate.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>
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>
Gets all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).static Collection<Thread>
Gets all active threads (A thread is active if it has been started and has not yet died).static ThreadGroup
Gets the system thread group (sometimes also referred as "root thread group").static void
Waits for the given thread to die for the given duration.static void
Sleeps the current thread for the given duration.
-
Field Details
-
ALWAYS_TRUE_PREDICATE
public static final edu.internet2.middleware.grouperClientExt.org.apache.commons.lang3.ThreadUtils.AlwaysTruePredicate ALWAYS_TRUE_PREDICATEPredicate which always returns true.
-
-
Constructor Details
-
ThreadUtils
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.
-
-
Method Details
-
findThreadById
Finds the active thread with the specified id.- Parameters:
threadId
- The thread id- Returns:
- The thread with the specified id or
null
if no such thread exists - Throws:
IllegalArgumentException
- 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 group
-
findThreadById
Finds the active thread with the specified id if it belongs to a thread group with the specified group name.- Parameters:
threadId
- The thread idthreadGroupName
- The thread group name- Returns:
- The threads which belongs to a thread group with the specified group name and the thread's id match the specified id.
null
is returned if no such thread exists - Throws:
IllegalArgumentException
- 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 group
-
findThreadById
Finds the active thread with the specified id if it belongs to the specified thread group.- Parameters:
threadId
- The thread idthreadGroup
- The thread group- Returns:
- The thread which belongs to a specified thread group and the thread's id match the specified id.
null
is returned if no such thread exists - Throws:
IllegalArgumentException
- 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 group
-
findThreadGroups
public 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).- Parameters:
group
- the thread grouprecurse
- iftrue
then evaluate the predicate recursively on all threadgroups in all subgroups of the given grouppredicate
- the predicate- Returns:
- An unmodifiable
Collection
of active threadgroups which match the given predicate and which is a subgroup of the given thread group - Throws:
IllegalArgumentException
- 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 group
-
findThreadGroups
Select all active threadgroups which match the given predicate.- Parameters:
predicate
- the predicate- Returns:
- An unmodifiable
Collection
of active threadgroups matching the given predicate - Throws:
IllegalArgumentException
- 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 group
-
findThreadGroupsByName
Finds active thread groups with the specified group name.- Parameters:
threadGroupName
- The thread group name- Returns:
- the thread groups with the specified group name or an empty collection if no such thread group exists. The collection returned is always unmodifiable.
- Throws:
IllegalArgumentException
- 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 group
-
findThreads
public 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).- Parameters:
group
- the thread grouprecurse
- iftrue
then evaluate the predicate recursively on all threads in all subgroups of the given grouppredicate
- the predicate- Returns:
- An unmodifiable
Collection
of active threads which match the given predicate and which belongs to the given thread group - Throws:
IllegalArgumentException
- 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 group
-
findThreads
Select all active threads which match the given predicate.- Parameters:
predicate
- the predicate- Returns:
- An unmodifiable
Collection
of active threads matching the given predicate - Throws:
IllegalArgumentException
- 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 group
-
findThreadsByName
Finds active threads with the specified name.- Parameters:
threadName
- The thread name- Returns:
- The threads with the specified name or an empty collection if no such thread exists. The collection returned is always unmodifiable.
- Throws:
IllegalArgumentException
- 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 group
-
findThreadsByName
Finds active threads with the specified name if they belong to a thread group with the specified group name.- Parameters:
threadName
- The thread namethreadGroupName
- The thread group name- Returns:
- The threads which belongs to a thread group with the specified group name and the thread's name match the specified name, An empty collection is returned if no such thread exists. The collection returned is always unmodifiable.
- Throws:
IllegalArgumentException
- 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 group
-
findThreadsByName
Finds active threads with the specified name if they belong to a specified thread group.- Parameters:
threadName
- The thread namethreadGroup
- The thread group- Returns:
- The threads which belongs to a thread group and the thread's name match the specified name, An empty collection is returned if no such thread exists. The collection returned is always unmodifiable.
- Throws:
IllegalArgumentException
- 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 group
-
getAllThreadGroups
Gets all active thread groups excluding the system thread group (A thread group is active if it has been not destroyed).- Returns:
- all thread groups excluding the system thread group. The collection returned is always unmodifiable.
- Throws:
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 group
-
getAllThreads
Gets all active threads (A thread is active if it has been started and has not yet died).- Returns:
- all active threads. The collection returned is always unmodifiable.
- Throws:
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 group
-
getSystemThreadGroup
Gets the system thread group (sometimes also referred as "root thread group").- Returns:
- the system thread group
- Throws:
SecurityException
- if the current thread cannot modify thread groups from this thread's thread group up to the system thread group
-
join
Waits for the given thread to die for the given duration. Implemented usingThread.join(long, int)
.- Parameters:
thread
- The thread to join.duration
- How long to wait.- Throws:
InterruptedException
- if any thread has interrupted the current thread.- Since:
- 3.12.0
- See Also:
-
sleep
Sleeps the current thread for the given duration. Implemented usingThread.sleep(long, int)
.- Parameters:
duration
- How long to sleep.- Throws:
InterruptedException
- if any thread has interrupted the current thread.- Since:
- 3.12.0
- See Also:
-