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
56 *java.lang.ThreadGroup(String)*
58 public ThreadGroup(java.lang.String name)
60 Constructs a new thread group. The parent of this new group is the thread group
61 of the currently running thread.
63 The checkAccess method of the parent thread group is called with no arguments;
64 this may result in a security exception.
66 name - the name of the new thread group.
68 *java.lang.ThreadGroup(ThreadGroup,String)*
71 java.lang.ThreadGroup parent,
72 java.lang.String name)
74 Creates a new thread group. The parent of this new group is the specified
77 The checkAccess method of the parent thread group is called with no arguments;
78 this may result in a security exception.
80 parent - the parent thread group.
81 name - the name of the new thread group.
83 *java.lang.ThreadGroup.activeCount()*
85 public int activeCount()
87 Returns an estimate of the number of active threads in this thread group. The
88 result might not reflect concurrent activity, and might be affected by the
89 presence of certain system threads.
91 Due to the inherently imprecise nature of the result, it is recommended that
92 this method only be used for informational purposes.
96 Returns: an estimate of the number of active threads in this thread group and in any
97 other thread group that has this thread group as an ancestor.
99 *java.lang.ThreadGroup.activeGroupCount()*
101 public int activeGroupCount()
103 Returns an estimate of the number of active groups in this thread group. The
104 result might not reflect concurrent activity.
106 Due to the inherently imprecise nature of the result, it is recommended that
107 this method only be used for informational purposes.
111 Returns: the number of active thread groups with this thread group as an ancestor.
113 *java.lang.ThreadGroup.allowThreadSuspension(boolean)*
115 public boolean allowThreadSuspension(boolean b)
117 Used by VM to control lowmem implicit suspension.
119 Deprecated: The definition of this call depends on {@link #suspend},
120 which is deprecated. Further, the behavior of this call
123 b - boolean to allow or disallow suspension
125 Returns: true on success
127 *java.lang.ThreadGroup.checkAccess()*
129 public final void checkAccess()
131 Determines if the currently running thread has permission to modify this thread
134 If there is a security manager, its checkAccess method is called with this
135 thread group as its argument. This may result in throwing a SecurityException.
139 *java.lang.ThreadGroup.destroy()*
141 public final void destroy()
143 Destroys this thread group and all of its subgroups. This thread group must be
144 empty, indicating that all threads that had been in this thread group have
147 First, the checkAccess method of this thread group is called with no arguments;
148 this may result in a security exception.
152 *java.lang.ThreadGroup.enumerate(Thread[])*
154 public int enumerate(java.lang.Thread[] list)
156 Copies into the specified array every active thread in this thread group and
159 First, the checkAccess method of this thread group is called with no arguments;
160 this may result in a security exception.
162 An application might use the activeCount method to get an estimate of how big
163 the array should be, however if the array is too short to hold all the threads,
164 the extra threads are silently ignored. If it is critical to obtain every
165 active thread in this thread group and its subgroups, the caller should verify
166 that the returned int value is strictly less than the length of list.
168 Due to the inherent race condition in this method, it is recommended that the
169 method only be used for informational purposes.
172 list - an array into which to place the list of threads.
174 Returns: the number of threads put into the array.
176 *java.lang.ThreadGroup.enumerate(Thread[],boolean)*
178 public int enumerate(
179 java.lang.Thread[] list,
182 Copies into the specified array every active thread in this thread group. If
183 the recurse flag is true, references to every active thread in this thread's
184 subgroups are also included. If the array is too short to hold all the threads,
185 the extra threads are silently ignored.
187 First, the checkAccess method of this thread group is called with no arguments;
188 this may result in a security exception.
190 An application might use the activeCount method to get an estimate of how big
191 the array should be, however if the array is too short to hold all the threads,
192 the extra threads are silently ignored. If it is critical to obtain every
193 active thread in this thread group, the caller should verify that the returned
194 int value is strictly less than the length of list.
196 Due to the inherent race condition in this method, it is recommended that the
197 method only be used for informational purposes.
200 list - an array into which to place the list of threads.
201 recurse - a flag indicating whether also to include threads in thread groups that are
202 subgroups of this thread group.
204 Returns: the number of threads placed into the array.
206 *java.lang.ThreadGroup.enumerate(ThreadGroup[])*
208 public int enumerate(java.lang.ThreadGroup[] list)
210 Copies into the specified array references to every active subgroup in this
213 First, the checkAccess method of this thread group is called with no arguments;
214 this may result in a security exception.
216 An application might use the activeGroupCount method to get an estimate of how
217 big the array should be, however if the array is too short to hold all the
218 thread groups, the extra thread groups are silently ignored. If it is critical
219 to obtain every active subgroup in this thread group, the caller should verify
220 that the returned int value is strictly less than the length of list.
222 Due to the inherent race condition in this method, it is recommended that the
223 method only be used for informational purposes.
226 list - an array into which to place the list of thread groups.
228 Returns: the number of thread groups put into the array.
230 *java.lang.ThreadGroup.enumerate(ThreadGroup[],boolean)*
232 public int enumerate(
233 java.lang.ThreadGroup[] list,
236 Copies into the specified array references to every active subgroup in this
237 thread group. If the recurse flag is true, references to all active subgroups
238 of the subgroups and so forth are also included.
240 First, the checkAccess method of this thread group is called with no arguments;
241 this may result in a security exception.
243 An application might use the activeGroupCount method to get an estimate of how
244 big the array should be, however if the array is too short to hold all the
245 thread groups, the extra thread groups are silently ignored. If it is critical
246 to obtain every active subgroup in this thread group, the caller should verify
247 that the returned int value is strictly less than the length of list.
249 Due to the inherent race condition in this method, it is recommended that the
250 method only be used for informational purposes.
253 list - an array into which to place the list of threads.
254 recurse - a flag indicating whether to recursively enumerate all included thread groups.
256 Returns: the number of thread groups put into the array.
258 *java.lang.ThreadGroup.getMaxPriority()*
260 public final int getMaxPriority()
262 Returns the maximum priority of this thread group. Threads that are part of
263 this group cannot have a higher priority than the maximum priority.
267 Returns: the maximum priority that a thread in this thread group can have.
269 *java.lang.ThreadGroup.getName()*
271 public final |java.lang.String| getName()
273 Returns the name of this thread group.
277 Returns: the name of this thread group.
279 *java.lang.ThreadGroup.getParent()*
281 public final |java.lang.ThreadGroup| getParent()
283 Returns the parent of this thread group.
285 First, if the parent is not null, the checkAccess method of the parent thread
286 group is called with no arguments; this may result in a security exception.
290 Returns: the parent of this thread group. The top-level thread group is the only thread
291 group whose parent is null.
293 *java.lang.ThreadGroup.interrupt()*
295 public final void interrupt()
297 Interrupts all threads in this thread group.
299 First, the checkAccess method of this thread group is called with no arguments;
300 this may result in a security exception.
302 This method then calls the interrupt method on all the threads in this thread
303 group and in all of its subgroups.
307 *java.lang.ThreadGroup.isDaemon()*
309 public final boolean isDaemon()
311 Tests if this thread group is a daemon thread group. A daemon thread group is
312 automatically destroyed when its last thread is stopped or its last thread
317 Returns: true if this thread group is a daemon thread group; false otherwise.
319 *java.lang.ThreadGroup.isDestroyed()*
321 public synchronized boolean isDestroyed()
323 Tests if this thread group has been destroyed.
327 Returns: true if this object is destroyed
329 *java.lang.ThreadGroup.list()*
333 Prints information about this thread group to the standard output. This method
334 is useful only for debugging.
338 *java.lang.ThreadGroup.parentOf(ThreadGroup)*
340 public final boolean parentOf(java.lang.ThreadGroup g)
342 Tests if this thread group is either the thread group argument or one of its
343 ancestor thread groups.
348 Returns: true if this thread group is the thread group argument or one of its ancestor
349 thread groups; false otherwise.
351 *java.lang.ThreadGroup.resume()*
353 public final void resume()
355 Resumes all threads in this thread group.
357 First, the checkAccess method of this thread group is called with no arguments;
358 this may result in a security exception.
360 This method then calls the resume method on all the threads in this thread
361 group and in all of its sub groups.
363 Deprecated: This method is used solely in conjunction with
364 <tt>Thread.suspend</tt> and <tt>ThreadGroup.suspend</tt>,
365 both of which have been deprecated, as they are inherently
366 deadlock-prone. See {@link Thread#suspend} for details.
369 *java.lang.ThreadGroup.setDaemon(boolean)*
371 public final void setDaemon(boolean daemon)
373 Changes the daemon status of this thread group.
375 First, the checkAccess method of this thread group is called with no arguments;
376 this may result in a security exception.
378 A daemon thread group is automatically destroyed when its last thread is
379 stopped or its last thread group is destroyed.
382 daemon - if true, marks this thread group as a daemon thread group; otherwise, marks
383 this thread group as normal.
385 *java.lang.ThreadGroup.setMaxPriority(int)*
387 public final void setMaxPriority(int pri)
389 Sets the maximum priority of the group. Threads in the thread group that
390 already have a higher priority are not affected.
392 First, the checkAccess method of this thread group is called with no arguments;
393 this may result in a security exception.
395 If the pri argument is less than (|java.lang.Thread|) or greater than
396 (|java.lang.Thread|) , the maximum priority of the group remains unchanged.
398 Otherwise, the priority of this ThreadGroup object is set to the smaller of the
399 specified pri and the maximum permitted priority of the parent of this thread
400 group. (If this thread group is the system thread group, which has no parent,
401 then its maximum priority is simply set to pri.) Then this method is called
402 recursively, with pri as its argument, for every thread group that belongs to
406 pri - the new priority of the thread group.
408 *java.lang.ThreadGroup.stop()*
410 public final void stop()
412 Stops all threads in this thread group.
414 First, the checkAccess method of this thread group is called with no arguments;
415 this may result in a security exception.
417 This method then calls the stop method on all the threads in this thread group
418 and in all of its subgroups.
420 Deprecated: This method is inherently unsafe. See
421 {@link Thread#stop} for details.
424 *java.lang.ThreadGroup.suspend()*
426 public final void suspend()
428 Suspends all threads in this thread group.
430 First, the checkAccess method of this thread group is called with no arguments;
431 this may result in a security exception.
433 This method then calls the suspend method on all the threads in this thread
434 group and in all of its subgroups.
436 Deprecated: This method is inherently deadlock-prone. See
437 {@link Thread#suspend} for details.
440 *java.lang.ThreadGroup.toString()*
442 public |java.lang.String| toString()
444 Returns a string representation of this Thread group.
448 Returns: a string representation of this thread group.
450 *java.lang.ThreadGroup.uncaughtException(Thread,Throwable)*
452 public void uncaughtException(
454 java.lang.Throwable e)
456 Called by the Java Virtual Machine when a thread in this thread group stops
457 because of an uncaught exception, and the thread does not have a specific
458 (|java.lang.Thread.UncaughtExceptionHandler|) installed.
460 The uncaughtException method of ThreadGroup does the following:
462 If this thread group has a parent thread group, the uncaughtException method of
463 that parent is called with the same two arguments. Otherwise, this method
464 checks to see if there is a default uncaught exception
465 handler(|java.lang.Thread|) installed, and if so, its uncaughtException method
466 is called with the same two arguments. Otherwise, this method determines if the
467 Throwable argument is an instance of (|java.lang.ThreadDeath|) . If so, nothing
468 special is done. Otherwise, a message containing the thread's name, as returned
469 from the thread's getName(|java.lang.Thread|) method, and a stack backtrace,
470 using the Throwable's printStackTrace(|java.lang.Throwable|) method, is printed
471 to the standard error stream(|java.lang.System|) .
473 Applications can override this method in subclasses of ThreadGroup to provide
474 alternative handling of uncaught exceptions.
477 t - the thread that is about to exit.
478 e - the uncaught exception.