java.lang
public class ThreadGroup extends Object implements Thread.UncaughtExceptionHandler
Thread
Constructor and Description |
---|
ThreadGroup(String name)
Create a new ThreadGroup using the given name and the current thread's
ThreadGroup as a parent.
|
ThreadGroup(ThreadGroup parent,
String name)
Create a new ThreadGroup using the given name and parent group.
|
Modifier and Type | Method and Description |
---|---|
int |
activeCount()
Return an estimate of the total number of active threads in this
ThreadGroup and all its descendants.
|
int |
activeGroupCount()
Get the number of active groups in this ThreadGroup.
|
boolean |
allowThreadSuspension(boolean allow)
Deprecated.
pointless, since suspend is deprecated
|
void |
checkAccess()
Find out if the current Thread can modify this ThreadGroup.
|
void |
destroy()
Destroy this ThreadGroup.
|
int |
enumerate(Thread[] array)
Copy all of the active Threads from this ThreadGroup and its descendants
into the specified array.
|
int |
enumerate(Thread[] array,
boolean recurse)
Copy all of the active Threads from this ThreadGroup and, if desired,
from its descendants, into the specified array.
|
int |
enumerate(ThreadGroup[] array)
Copy all active ThreadGroups that are descendants of this ThreadGroup
into the specified array.
|
int |
enumerate(ThreadGroup[] array,
boolean recurse)
Copy all active ThreadGroups that are children of this ThreadGroup into
the specified array, and if desired, also all descendents.
|
int |
getMaxPriority()
Get the maximum priority of Threads in this ThreadGroup.
|
String |
getName()
Get the name of this ThreadGroup.
|
ThreadGroup |
getParent()
Get the parent of this ThreadGroup.
|
void |
interrupt()
Interrupt all Threads in this ThreadGroup and its sub-groups.
|
boolean |
isDaemon()
Tell whether this ThreadGroup is a daemon group.
|
boolean |
isDestroyed()
Tell whether this ThreadGroup has been destroyed or not.
|
void |
list()
Print out information about this ThreadGroup to System.out.
|
boolean |
parentOf(ThreadGroup group)
Check whether this ThreadGroup is an ancestor of the specified
ThreadGroup, or if they are the same.
|
void |
resume()
Deprecated.
pointless, since suspend is deprecated
|
void |
setDaemon(boolean daemon)
Set whether this ThreadGroup is a daemon group.
|
void |
setMaxPriority(int maxpri)
Set the maximum priority for Threads in this ThreadGroup. setMaxPriority
can only be used to reduce the current maximum.
|
void |
stop()
Deprecated.
unsafe operation, try not to use
|
void |
suspend()
Deprecated.
unsafe operation, try not to use
|
String |
toString()
Return a human-readable String representing this ThreadGroup.
|
void |
uncaughtException(Thread thread,
Throwable t)
When a Thread in this ThreadGroup does not catch an exception, the
virtual machine calls this method.
|
public ThreadGroup(String name)
checkAccess
.name
- the name to use for the ThreadGroupSecurityException
- if the current thread cannot create a groupcheckAccess()
public ThreadGroup(ThreadGroup parent, String name)
checkAccess
.name
- the name to use for the ThreadGroupparent
- the ThreadGroup to use as a parentNullPointerException
- if parent is nullSecurityException
- if the current thread cannot create a groupIllegalThreadStateException
- if the parent is destroyedcheckAccess()
public final String getName()
public final ThreadGroup getParent()
checkAccess
.SecurityException
- if permission is deniedpublic final int getMaxPriority()
public final boolean isDaemon()
public boolean isDestroyed()
public final void setDaemon(boolean daemon)
checkAccess
.daemon
- whether this ThreadGroup should be a daemon groupSecurityException
- if you cannot modify this ThreadGroupcheckAccess()
public final void setMaxPriority(int maxpri)
checkAccess
.maxpri
- the new maximum priority for this ThreadGroupSecurityException
- if you cannot modify this ThreadGroupgetMaxPriority()
,
checkAccess()
public final boolean parentOf(ThreadGroup group)
group
- the group to test onpublic final void checkAccess()
SecurityManager.checkAccess(this)
.SecurityException
- if the current Thread cannot modify this
ThreadGroupSecurityManager.checkAccess(ThreadGroup)
public int activeCount()
public int enumerate(Thread[] array)
checkAccess
.array
- the array to put the threads intoSecurityException
- if permission was deniedNullPointerException
- if array is nullArrayStoreException
- if a thread does not fit in the arrayactiveCount()
,
checkAccess()
,
enumerate(Thread[], boolean)
public int enumerate(Thread[] array, boolean recurse)
checkAccess
.array
- the array to put the threads intorecurse
- whether to recurse into descendent ThreadGroupsSecurityException
- if permission was deniedNullPointerException
- if array is nullArrayStoreException
- if a thread does not fit in the arrayactiveCount()
,
checkAccess()
public int activeGroupCount()
public int enumerate(ThreadGroup[] array)
checkAccess
.array
- the array to put the ThreadGroups intoSecurityException
- if permission was deniedNullPointerException
- if array is nullArrayStoreException
- if a group does not fit in the arrayactiveCount()
,
checkAccess()
,
enumerate(ThreadGroup[], boolean)
public int enumerate(ThreadGroup[] array, boolean recurse)
checkAccess
.array
- the array to put the ThreadGroups intorecurse
- whether to recurse into descendent ThreadGroupsSecurityException
- if permission was deniedNullPointerException
- if array is nullArrayStoreException
- if a group does not fit in the arrayactiveCount()
,
checkAccess()
public final void stop()
This is inherently unsafe, as it can interrupt synchronized blocks and
leave data in bad states. Hence, there is a security check:
checkAccess()
, followed by further checks on each thread
being stopped.
SecurityException
- if permission is deniedcheckAccess()
,
Thread.stop(Throwable)
public final void interrupt()
checkAccess
.SecurityException
- if permission is deniedcheckAccess()
,
Thread.interrupt()
public final void suspend()
This is inherently unsafe, as suspended threads still hold locks,
which can lead to deadlock. Hence, there is a security check:
checkAccess()
, followed by further checks on each thread
being suspended.
SecurityException
- if permission is deniedcheckAccess()
,
Thread.suspend()
public final void resume()
checkAccess()
, followed by further checks on each thread
being resumed.SecurityException
- if permission is deniedcheckAccess()
,
Thread.suspend()
public final void destroy()
checkAccess
.IllegalThreadStateException
- if the ThreadGroup is not empty, or
was previously destroyedSecurityException
- if permission is deniedcheckAccess()
public void list()
public void uncaughtException(Thread thread, Throwable t)
uncaughtException
in interface Thread.UncaughtExceptionHandler
thread
- the thread that exitedt
- the uncaught throwableNullPointerException
- if t is nullThreadDeath
,
System.err
,
Throwable.printStackTrace()
public boolean allowThreadSuspension(boolean allow)
allow
- whether to allow low-memory thread suspension; ignoredpublic String toString()
getClass().getName() + "[name=" + getName() + ",maxpri="
+ getMaxPriority() + ']'
.toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)