1 *java.lang.ThreadGroup* *ThreadGroup* A thread group represents a set of threads
3 public class ThreadGroup
4 extends |java.lang.Object|
5 implements |java.lang.Thread.UncaughtExceptionHandler|
7 |java.lang.ThreadGroup_Description|
8 |java.lang.ThreadGroup_Fields|
9 |java.lang.ThreadGroup_Constructors|
10 |java.lang.ThreadGroup_Methods|
12 ================================================================================
14 *java.lang.ThreadGroup_Constructors*
15 |java.lang.ThreadGroup(String)|Constructs a new thread group.
16 |java.lang.ThreadGroup(ThreadGroup,String)|Creates a new thread group.
18 *java.lang.ThreadGroup_Methods*
19 |java.lang.ThreadGroup.activeCount()|Returns an estimate of the number of activ
20 |java.lang.ThreadGroup.activeGroupCount()|Returns an estimate of the number of
21 |java.lang.ThreadGroup.allowThreadSuspension(boolean)|Used by VM to control low
22 |java.lang.ThreadGroup.checkAccess()|Determines if the currently running thread
23 |java.lang.ThreadGroup.destroy()|Destroys this thread group and all of its subg
24 |java.lang.ThreadGroup.enumerate(Thread[])|Copies into the specified array ever
25 |java.lang.ThreadGroup.enumerate(Thread[],boolean)|Copies into the specified ar
26 |java.lang.ThreadGroup.enumerate(ThreadGroup[])|Copies into the specified array
27 |java.lang.ThreadGroup.enumerate(ThreadGroup[],boolean)|Copies into the specifi
28 |java.lang.ThreadGroup.getMaxPriority()|Returns the maximum priority of this th
29 |java.lang.ThreadGroup.getName()|Returns the name of this thread group.
30 |java.lang.ThreadGroup.getParent()|Returns the parent of this thread group.
31 |java.lang.ThreadGroup.interrupt()|Interrupts all threads in this thread group.
32 |java.lang.ThreadGroup.isDaemon()|Tests if this thread group is a daemon thread
33 |java.lang.ThreadGroup.isDestroyed()|Tests if this thread group has been destro
34 |java.lang.ThreadGroup.list()|Prints information about this thread group to the
35 |java.lang.ThreadGroup.parentOf(ThreadGroup)|Tests if this thread group is eith
36 |java.lang.ThreadGroup.resume()|Resumes all threads in this thread group.
37 |java.lang.ThreadGroup.setDaemon(boolean)|Changes the daemon status of this thr
38 |java.lang.ThreadGroup.setMaxPriority(int)|Sets the maximum priority of the gro
39 |java.lang.ThreadGroup.stop()|Stops all threads in this thread group.
40 |java.lang.ThreadGroup.suspend()|Suspends all threads in this thread group.
41 |java.lang.ThreadGroup.toString()|Returns a string representation of this Threa
42 |java.lang.ThreadGroup.uncaughtException(Thread,Throwable)|Called by the Java V
44 *java.lang.ThreadGroup_Description*
46 A thread group represents a set of threads. In addition, a thread group can
47 also include other thread groups. The thread groups form a tree in which every
48 thread group except the initial thread group has a parent.
50 A thread is allowed to access information about its own thread group, but not
51 to access information about its thread group's parent thread group or any other
55 *java.lang.ThreadGroup(String)*
57 public ThreadGroup(java.lang.String name)
59 Constructs a new thread group. The parent of this new group is the thread group
60 of the currently running thread.
62 The checkAccess method of the parent thread group is called with no arguments;
63 this may result in a security exception.
65 name - the name of the new thread group.
67 *java.lang.ThreadGroup(ThreadGroup,String)*
70 java.lang.ThreadGroup parent,
71 java.lang.String name)
73 Creates a new thread group. The parent of this new group is the specified
76 The checkAccess method of the parent thread group is called with no arguments;
77 this may result in a security exception.
79 parent - the parent thread group.
80 name - the name of the new thread group.
82 *java.lang.ThreadGroup.activeCount()*
84 public int activeCount()
86 Returns an estimate of the number of active threads in this thread group. The
87 result might not reflect concurrent activity, and might be affected by the
88 presence of certain system threads.
90 Due to the inherently imprecise nature of the result, it is recommended that
91 this method only be used for informational purposes.
94 Returns: an estimate of the number of active threads in this thread group and in any
95 other thread group that has this thread group as an ancestor.
96 *java.lang.ThreadGroup.activeGroupCount()*
98 public int activeGroupCount()
100 Returns an estimate of the number of active groups in this thread group. The
101 result might not reflect concurrent activity.
103 Due to the inherently imprecise nature of the result, it is recommended that
104 this method only be used for informational purposes.
107 Returns: the number of active thread groups with this thread group as an ancestor.
108 *java.lang.ThreadGroup.allowThreadSuspension(boolean)*
110 public boolean allowThreadSuspension(boolean b)
112 Used by VM to control lowmem implicit suspension.
114 b - boolean to allow or disallow suspension
116 Returns: true on success
117 *java.lang.ThreadGroup.checkAccess()*
119 public final void checkAccess()
121 Determines if the currently running thread has permission to modify this thread
124 If there is a security manager, its checkAccess method is called with this
125 thread group as its argument. This may result in throwing a SecurityException.
128 *java.lang.ThreadGroup.destroy()*
130 public final void destroy()
132 Destroys this thread group and all of its subgroups. This thread group must be
133 empty, indicating that all threads that had been in this thread group have
136 First, the checkAccess method of this thread group is called with no arguments;
137 this may result in a security exception.
140 *java.lang.ThreadGroup.enumerate(Thread[])*
142 public int enumerate(java.lang.Thread[] list)
144 Copies into the specified array every active thread in this thread group and
147 First, the checkAccess method of this thread group is called with no arguments;
148 this may result in a security exception.
150 An application might use the activeCount method to get an estimate of how big
151 the array should be, however if the array is too short to hold all the threads,
152 the extra threads are silently ignored. If it is critical to obtain every
153 active thread in this thread group and its subgroups, the caller should verify
154 that the returned int value is strictly less than the length of list.
156 Due to the inherent race condition in this method, it is recommended that the
157 method only be used for informational purposes.
159 list - an array into which to place the list of threads.
161 Returns: the number of threads put into the array.
162 *java.lang.ThreadGroup.enumerate(Thread[],boolean)*
164 public int enumerate(
165 java.lang.Thread[] list,
168 Copies into the specified array every active thread in this thread group. If
169 the recurse flag is true, references to every active thread in this thread's
170 subgroups are also included. If the array is too short to hold all the threads,
171 the extra threads are silently ignored.
173 First, the checkAccess method of this thread group is called with no arguments;
174 this may result in a security exception.
176 An application might use the activeCount method to get an estimate of how big
177 the array should be, however if the array is too short to hold all the threads,
178 the extra threads are silently ignored. If it is critical to obtain every
179 active thread in this thread group, the caller should verify that the returned
180 int value is strictly less than the length of list.
182 Due to the inherent race condition in this method, it is recommended that the
183 method only be used for informational purposes.
185 list - an array into which to place the list of threads.
186 recurse - a flag indicating whether also to include threads in thread groups that are
187 subgroups of this thread group.
189 Returns: the number of threads placed into the array.
190 *java.lang.ThreadGroup.enumerate(ThreadGroup[])*
192 public int enumerate(java.lang.ThreadGroup[] list)
194 Copies into the specified array references to every active subgroup in this
197 First, the checkAccess method of this thread group is called with no arguments;
198 this may result in a security exception.
200 An application might use the activeGroupCount method to get an estimate of how
201 big the array should be, however if the array is too short to hold all the
202 thread groups, the extra thread groups are silently ignored. If it is critical
203 to obtain every active subgroup in this thread group, the caller should verify
204 that the returned int value is strictly less than the length of list.
206 Due to the inherent race condition in this method, it is recommended that the
207 method only be used for informational purposes.
209 list - an array into which to place the list of thread groups.
211 Returns: the number of thread groups put into the array.
212 *java.lang.ThreadGroup.enumerate(ThreadGroup[],boolean)*
214 public int enumerate(
215 java.lang.ThreadGroup[] list,
218 Copies into the specified array references to every active subgroup in this
219 thread group. If the recurse flag is true, references to all active subgroups
220 of the subgroups and so forth are also included.
222 First, the checkAccess method of this thread group is called with no arguments;
223 this may result in a security exception.
225 An application might use the activeGroupCount method to get an estimate of how
226 big the array should be, however if the array is too short to hold all the
227 thread groups, the extra thread groups are silently ignored. If it is critical
228 to obtain every active subgroup in this thread group, the caller should verify
229 that the returned int value is strictly less than the length of list.
231 Due to the inherent race condition in this method, it is recommended that the
232 method only be used for informational purposes.
234 list - an array into which to place the list of threads.
235 recurse - a flag indicating whether to recursively enumerate all included thread groups.
237 Returns: the number of thread groups put into the array.
238 *java.lang.ThreadGroup.getMaxPriority()*
240 public final int getMaxPriority()
242 Returns the maximum priority of this thread group. Threads that are part of
243 this group cannot have a higher priority than the maximum priority.
246 Returns: the maximum priority that a thread in this thread group can have.
247 *java.lang.ThreadGroup.getName()*
249 public final |java.lang.String| getName()
251 Returns the name of this thread group.
254 Returns: the name of this thread group.
255 *java.lang.ThreadGroup.getParent()*
257 public final |java.lang.ThreadGroup| getParent()
259 Returns the parent of this thread group.
261 First, if the parent is not null, the checkAccess method of the parent thread
262 group is called with no arguments; this may result in a security exception.
265 Returns: the parent of this thread group. The top-level thread group is the only thread
266 group whose parent is null.
267 *java.lang.ThreadGroup.interrupt()*
269 public final void interrupt()
271 Interrupts all threads in this thread group.
273 First, the checkAccess method of this thread group is called with no arguments;
274 this may result in a security exception.
276 This method then calls the interrupt method on all the threads in this thread
277 group and in all of its subgroups.
280 *java.lang.ThreadGroup.isDaemon()*
282 public final boolean isDaemon()
284 Tests if this thread group is a daemon thread group. A daemon thread group is
285 automatically destroyed when its last thread is stopped or its last thread
289 Returns: true if this thread group is a daemon thread group; false otherwise.
290 *java.lang.ThreadGroup.isDestroyed()*
292 public synchronized boolean isDestroyed()
294 Tests if this thread group has been destroyed.
297 Returns: true if this object is destroyed
298 *java.lang.ThreadGroup.list()*
302 Prints information about this thread group to the standard output. This method
303 is useful only for debugging.
306 *java.lang.ThreadGroup.parentOf(ThreadGroup)*
308 public final boolean parentOf(java.lang.ThreadGroup g)
310 Tests if this thread group is either the thread group argument or one of its
311 ancestor thread groups.
315 Returns: true if this thread group is the thread group argument or one of its ancestor
316 thread groups; false otherwise.
317 *java.lang.ThreadGroup.resume()*
319 public final void resume()
321 Resumes all threads in this thread group.
323 First, the checkAccess method of this thread group is called with no arguments;
324 this may result in a security exception.
326 This method then calls the resume method on all the threads in this thread
327 group and in all of its sub groups.
330 *java.lang.ThreadGroup.setDaemon(boolean)*
332 public final void setDaemon(boolean daemon)
334 Changes the daemon status of this thread group.
336 First, the checkAccess method of this thread group is called with no arguments;
337 this may result in a security exception.
339 A daemon thread group is automatically destroyed when its last thread is
340 stopped or its last thread group is destroyed.
342 daemon - if true, marks this thread group as a daemon thread group; otherwise, marks
343 this thread group as normal.
345 *java.lang.ThreadGroup.setMaxPriority(int)*
347 public final void setMaxPriority(int pri)
349 Sets the maximum priority of the group. Threads in the thread group that
350 already have a higher priority are not affected.
352 First, the checkAccess method of this thread group is called with no arguments;
353 this may result in a security exception.
355 If the pri argument is less than (|java.lang.Thread|) or greater than
356 (|java.lang.Thread|) , the maximum priority of the group remains unchanged.
358 Otherwise, the priority of this ThreadGroup object is set to the smaller of the
359 specified pri and the maximum permitted priority of the parent of this thread
360 group. (If this thread group is the system thread group, which has no parent,
361 then its maximum priority is simply set to pri.) Then this method is called
362 recursively, with pri as its argument, for every thread group that belongs to
365 pri - the new priority of the thread group.
367 *java.lang.ThreadGroup.stop()*
369 public final void stop()
371 Stops all threads in this thread group.
373 First, the checkAccess method of this thread group is called with no arguments;
374 this may result in a security exception.
376 This method then calls the stop method on all the threads in this thread group
377 and in all of its subgroups.
380 *java.lang.ThreadGroup.suspend()*
382 public final void suspend()
384 Suspends all threads in this thread group.
386 First, the checkAccess method of this thread group is called with no arguments;
387 this may result in a security exception.
389 This method then calls the suspend method on all the threads in this thread
390 group and in all of its subgroups.
393 *java.lang.ThreadGroup.toString()*
395 public |java.lang.String| toString()
397 Returns a string representation of this Thread group.
400 Returns: a string representation of this thread group.
401 *java.lang.ThreadGroup.uncaughtException(Thread,Throwable)*
403 public void uncaughtException(
405 java.lang.Throwable e)
407 Called by the Java Virtual Machine when a thread in this thread group stops
408 because of an uncaught exception, and the thread does not have a specific
409 (|java.lang.Thread.UncaughtExceptionHandler|) installed.
411 The uncaughtException method of ThreadGroup does the following:
413 If this thread group has a parent thread group, the uncaughtException method of
414 that parent is called with the same two arguments. Otherwise, this method
415 checks to see if there is a default uncaught exception
416 handler(|java.lang.Thread|) installed, and if so, its uncaughtException method
417 is called with the same two arguments. Otherwise, this method determines if the
418 Throwable argument is an instance of (|java.lang.ThreadDeath|) . If so, nothing
419 special is done. Otherwise, a message containing the thread's name, as returned
420 from the thread's getName(|java.lang.Thread|) method, and a stack backtrace,
421 using the Throwable's printStackTrace(|java.lang.Throwable|) method, is printed
422 to the standard error stream(|java.lang.System|) .
424 Applications can override this method in subclasses of ThreadGroup to provide
425 alternative handling of uncaught exceptions.
427 t - the thread that is about to exit.
428 e - the uncaught exception.