java.lang
Class ThreadGroup
- Thread.UncaughtExceptionHandler
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.
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.
|
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) - pointless, since suspend is deprecated
|
void | checkAccess() - Find out if the current Thread can modify this ThreadGroup.
|
void | destroy() - Destroy this ThreadGroup.
|
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 | 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 | 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() - 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() - unsafe operation, try not to use
|
void | suspend() - 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.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
ThreadGroup
public ThreadGroup(String name)
Create a new ThreadGroup using the given name and the current thread's
ThreadGroup as a parent. There may be a security check,
checkAccess
.
name
- the name to use for the ThreadGroup
ThreadGroup
public ThreadGroup(ThreadGroup parent,
String name)
Create a new ThreadGroup using the given name and parent group. The new
group inherits the maximum priority and daemon status of its parent
group. There may be a security check, checkAccess
.
parent
- the ThreadGroup to use as a parentname
- the name to use for the ThreadGroup
activeCount
public int activeCount()
Return an estimate of the total number of active threads in this
ThreadGroup and all its descendants. This cannot return an exact number,
since the status of threads may change after they were counted; but it
should be pretty close. Based on a JDC bug,
4089701, we take active to mean isAlive().
- count of active threads in this ThreadGroup and its descendants
activeGroupCount
public int activeGroupCount()
Get the number of active groups in this ThreadGroup. This group itself
is not included in the count. A sub-group is active if it has not been
destroyed. This cannot return an exact number, since the status of
threads may change after they were counted; but it should be pretty close.
- the number of active groups in this ThreadGroup
allowThreadSuspension
public boolean allowThreadSuspension(boolean allow)
pointless, since suspend is deprecated
Originally intended to tell the VM whether it may suspend Threads in
low memory situations, this method was never implemented by Sun, and
is hence a no-op.
allow
- whether to allow low-memory thread suspension; ignored
checkAccess
public final void checkAccess()
Find out if the current Thread can modify this ThreadGroup. This passes
the check on to SecurityManager.checkAccess(this)
.
destroy
public final void destroy()
Destroy this ThreadGroup. The group must be empty, meaning that all
threads and sub-groups have completed execution. Daemon groups are
destroyed automatically. There may be a security check,
checkAccess
.
enumerate
public int enumerate(ThreadGroup[] array)
Copy all active ThreadGroups that are descendants of this ThreadGroup
into the specified array. If the array is not large enough to hold all
active ThreadGroups, extra ThreadGroups simply will not be copied. There
may be a security check, checkAccess
.
array
- the array to put the ThreadGroups into
- the number of ThreadGroups copied into the array
enumerate
public 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. If the array
is not large enough to hold all active ThreadGroups, extra ThreadGroups
simply will not be copied. There may be a security check,
checkAccess
.
array
- the array to put the ThreadGroups intorecurse
- whether to recurse into descendent ThreadGroups
- the number of ThreadGroups copied into the array
enumerate
public int enumerate(Thread[] array)
Copy all of the active Threads from this ThreadGroup and its descendants
into the specified array. If the array is not big enough to hold all
the Threads, extra Threads will simply not be copied. There may be a
security check, checkAccess
.
array
- the array to put the threads into
- the number of threads put into the array
enumerate
public 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. If the array is not big
enough to hold all the Threads, extra Threads will simply not be copied.
There may be a security check, checkAccess
.
array
- the array to put the threads intorecurse
- whether to recurse into descendent ThreadGroups
- the number of threads put into the array
getMaxPriority
public final int getMaxPriority()
Get the maximum priority of Threads in this ThreadGroup. Threads created
after this call in this group may not exceed this priority.
- the maximum priority of Threads in this ThreadGroup
getName
public final String getName()
Get the name of this ThreadGroup.
- the name of this ThreadGroup
getParent
public final ThreadGroup getParent()
Get the parent of this ThreadGroup. If the parent is not null, there
may be a security check, checkAccess
.
- the parent of this ThreadGroup
interrupt
public final void interrupt()
Interrupt all Threads in this ThreadGroup and its sub-groups. There may
be a security check, checkAccess
.
isDaemon
public final boolean isDaemon()
Tell whether this ThreadGroup is a daemon group. A daemon group will
be automatically destroyed when its last thread is stopped and
its last thread group is destroyed.
- whether this ThreadGroup is a daemon group
isDestroyed
public boolean isDestroyed()
Tell whether this ThreadGroup has been destroyed or not.
- whether this ThreadGroup has been destroyed or not
list
public void list()
Print out information about this ThreadGroup to System.out. This is
meant for debugging purposes. WARNING: This method is not secure,
and can print the name of threads to standard out even when you cannot
otherwise get at such threads.
parentOf
public final boolean parentOf(ThreadGroup group)
Check whether this ThreadGroup is an ancestor of the specified
ThreadGroup, or if they are the same.
group
- the group to test on
- whether this ThreadGroup is a parent of the specified group
resume
public final void resume()
pointless, since suspend is deprecated
Resume all suspended Threads in this ThreadGroup and its descendants.
To mirror suspend(), there is a security check:
checkAccess()
, followed by further checks on each thread
being resumed.
setDaemon
public final void setDaemon(boolean daemon)
Set whether this ThreadGroup is a daemon group. A daemon group will be
destroyed when its last thread is stopped and its last thread group is
destroyed. There may be a security check, checkAccess
.
daemon
- whether this ThreadGroup should be a daemon group
setMaxPriority
public final void setMaxPriority(int maxpri)
Set the maximum priority for Threads in this ThreadGroup. setMaxPriority
can only be used to reduce the current maximum. If maxpri is greater
than the current Maximum of the parent group, the current value is not
changed. Otherwise, all groups which belong to this have their priority
adjusted as well. Calling this does not affect threads already in this
ThreadGroup. There may be a security check, checkAccess
.
maxpri
- the new maximum priority for this ThreadGroup
stop
public final void stop()
unsafe operation, try not to use
Stop all Threads in this ThreadGroup and its descendants.
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.
suspend
public final void suspend()
unsafe operation, try not to use
Suspend all Threads in this ThreadGroup and its descendants.
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.
toString
public String toString()
Return a human-readable String representing this ThreadGroup. The format
of the string is:
getClass().getName() + "[name=" + getName() + ",maxpri="
+ getMaxPriority() + ']'
.
- toString in interface Object
- a human-readable String representing this ThreadGroup
uncaughtException
public void uncaughtException(Thread thread,
Throwable t)
When a Thread in this ThreadGroup does not catch an exception, the
virtual machine calls this method. The default implementation simply
passes the call to the parent; then in top ThreadGroup, it will
ignore ThreadDeath and print the stack trace of any other throwable.
Override this method if you want to handle the exception in a different
manner.
- uncaughtException in interface Thread.UncaughtExceptionHandler
thread
- the thread that exitedt
- the uncaught throwable
ThreadGroup -- a group of Threads
Copyright (C) 1998, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.