public final class ThreadUtilities
extends java.lang.Object
Please see the accompanying article: Java tip: How to list and find threads and thread groups
Modifier and Type | Method and Description |
---|---|
static java.lang.Thread[] |
getAllDaemonThreads()
Get a list of all daemon threads.
|
static java.lang.ThreadGroup[] |
getAllThreadGroups()
Get a list of all thread groups.
|
static java.lang.management.ThreadInfo[] |
getAllThreadInfos()
Get a list of all thread info objects.
|
static java.lang.Thread[] |
getAllThreads()
Get a list of all threads.
|
static java.lang.Thread[] |
getAllThreads(java.lang.Thread.State state)
Get a list of all threads with a given thread state.
|
static java.lang.Thread[] |
getAllThreadsPrioritized()
Get a list of all threads, sorted from highest to
lowest priority.
|
static java.lang.Thread |
getBlockingThread(java.lang.Thread blockedThread)
Get the thread who's lock is blocking the given thread.
|
static java.lang.Thread[] |
getGroupThreads(java.lang.String name)
Get a list of all threads in a named thread group.
|
static java.lang.Thread[] |
getGroupThreads(java.lang.ThreadGroup group)
Get a list of all threads in a thread group.
|
static java.lang.Thread |
getLockingThread(java.lang.Object object)
Get the thread holding a lock on the given object.
|
static java.lang.ThreadGroup |
getRootThreadGroup()
Get the root thread group in the thread group tree.
|
static java.lang.Thread |
getThread(long id)
Get the thread with the given ID.
|
static java.lang.Thread |
getThread(java.lang.String name)
Get the thread with the given name.
|
static java.lang.Thread |
getThread(java.lang.management.ThreadInfo info)
Get the thread for the given thread info.
|
static java.lang.ThreadGroup |
getThreadGroup(java.lang.String name)
Get the thread group with the given name.
|
static java.lang.management.ThreadInfo |
getThreadInfo(long id)
Get the thread info for the thread with the given ID.
|
static java.lang.management.ThreadInfo |
getThreadInfo(java.lang.String name)
Get the thread info for the thread with the given name.
|
static java.lang.management.ThreadInfo |
getThreadInfo(java.lang.Thread thread)
Get the thread info for the given thread.
|
public static java.lang.ThreadGroup getRootThreadGroup()
public static java.lang.ThreadGroup[] getAllThreadGroups()
public static java.lang.ThreadGroup getThreadGroup(java.lang.String name)
name
- the thread group name to search forjava.lang.NullPointerException
- if the name is nullpublic static java.lang.Thread[] getAllThreads()
public static java.lang.Thread[] getGroupThreads(java.lang.ThreadGroup group)
group
- the thread group to listjava.lang.NullPointerException
- if the group is nullpublic static java.lang.Thread[] getGroupThreads(java.lang.String name)
name
- the name of the thread groupjava.lang.NullPointerException
- if the name is nullpublic static java.lang.Thread[] getAllThreadsPrioritized()
public static java.lang.Thread[] getAllDaemonThreads()
public static java.lang.Thread[] getAllThreads(java.lang.Thread.State state)
state
- the state to look forpublic static java.lang.Thread getThread(java.lang.String name)
name
- the thread name to search forjava.lang.NullPointerException
- if the name is nullpublic static java.lang.Thread getThread(long id)
id
- the thread ID to search forpublic static java.lang.Thread getThread(java.lang.management.ThreadInfo info)
info
- the thread info to search forjava.lang.NullPointerException
- if info is nullpublic static java.lang.management.ThreadInfo[] getAllThreadInfos()
public static java.lang.management.ThreadInfo getThreadInfo(java.lang.String name)
name
- the thread name to search forjava.lang.NullPointerException
- if the name is nullpublic static java.lang.management.ThreadInfo getThreadInfo(long id)
id
- the thread ID to search forjava.lang.IllegalArgumentException
- if id <= 0public static java.lang.management.ThreadInfo getThreadInfo(java.lang.Thread thread)
thread
- the thread to search forjava.lang.NullPointerException
- if thread is nullpublic static java.lang.Thread getLockingThread(java.lang.Object object)
object
- the object to look for a lock onjava.lang.NullPointerException
- if the object is nullpublic static java.lang.Thread getBlockingThread(java.lang.Thread blockedThread)
blockedThread
- the blocked threadjava.lang.NullPointerException
- if the blocked thread is null