|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.ThreadGroup
public class ThreadGroup
ThreadGroup allows you to group Threads together. There is a hierarchy of ThreadGroups, and only the initial ThreadGroup has no parent. A Thread may access information about its own ThreadGroup, but not its parents or others outside the tree.
Thread
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ThreadGroup(String name)
checkAccess
.
name
- the name to use for the ThreadGroup
SecurityException
- 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 parent
NullPointerException
- if parent is null
SecurityException
- if the current thread cannot create a group
IllegalThreadStateException
- if the parent is destroyedcheckAccess()
Method Detail |
---|
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 group
SecurityException
- if you cannot modify this ThreadGroupcheckAccess()
public final void setMaxPriority(int maxpri)
checkAccess
.
maxpri
- the new maximum priority for this ThreadGroup
SecurityException
- if you cannot modify this ThreadGroupgetMaxPriority()
,
checkAccess()
public final boolean parentOf(ThreadGroup group)
group
- the group to test on
public 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 into
SecurityException
- if permission was denied
NullPointerException
- if array is null
ArrayStoreException
- 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 ThreadGroups
SecurityException
- if permission was denied
NullPointerException
- if array is null
ArrayStoreException
- 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 into
SecurityException
- if permission was denied
NullPointerException
- if array is null
ArrayStoreException
- 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 ThreadGroups
SecurityException
- if permission was denied
NullPointerException
- if array is null
ArrayStoreException
- 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 destroyed
SecurityException
- 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 throwable
NullPointerException
- if t is nullThreadDeath
,
System.err
,
Throwable.printStackTrace()
public boolean allowThreadSuspension(boolean allow)
allow
- whether to allow low-memory thread suspension; ignored
public String toString()
getClass().getName() + "[name=" + getName() + ",maxpri="
+ getMaxPriority() + ']'
.
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |