Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
ThreadGroup

This class represents a group of threads and allows that group to be manipulated as a whole. A ThreadGroup can contain Thread objects, as well as other child ThreadGroup objects. All ThreadGroup objects are created as children of some other ThreadGroup, and thus there is a parent/child hierarchy of ThreadGroup objects. Use getParent( ) to obtain the parent ThreadGroup, and use activeCount( ) , activeGroupCount( ), and the various enumerate( ) methods to list the child Thread and ThreadGroup objects. Most applications can simply rely on the default system thread group. System-level code and applications such as servers that need to create a large number of threads may find it convenient to create their own ThreadGroup objects, however.

interrupt( ) interrupts all threads in the group at once. setMaxPriority( ) specifies the maximum priority any thread in the group can have. checkAccess( ) checks whether the calling thread has permission to modify the given thread group. The method throws a SecurityException if the current thread does not have access. uncaughtException( ) contains the code that is run when a thread terminates because of an uncaught exception or error. You can customize this method by subclassing ThreadGroup.

Figure 10-65. java.lang.ThreadGroup


public class ThreadGroup implements Thread.UncaughtExceptionHandler {
// Public Constructors
     public ThreadGroup(String name);  
     public ThreadGroup(ThreadGroup parent, String name);  
// Public Instance Methods
     public int activeCount( );  
     public int activeGroupCount( );  
     public final void checkAccess( );  
     public final void destroy( );  
     public int enumerate(ThreadGroup[ ] list);  
     public int enumerate(Thread[ ] list);  
     public int enumerate(Thread[ ] list, boolean recurse);  
     public int enumerate(ThreadGroup[ ] list, boolean recurse);  
     public final int getMaxPriority( );  
     public final String getName( );  
     public final ThreadGroup getParent( );  
1.2  public final void interrupt( );  
     public final boolean isDaemon( );  
1.1  public boolean isDestroyed( );                 synchronized
     public void list( );  
     public final boolean parentOf(ThreadGroup g);  
     public final void setDaemon(boolean daemon);  
     public final void setMaxPriority(int pri);  
     public void uncaughtException(Thread t, Throwable e); 
Implements:Thread.UncaughtExceptionHandler
// Methods Implementing Thread.UncaughtExceptionHandler
     public void uncaughtException(Thread t, Throwable e);  
// Public Methods Overriding Object
     public String toString( );  
// Deprecated Public Methods
                  1.1#  public boolean allowThreadSuspension(boolean b);  
#    public final void resume( );  
#    public final void stop( );  
#    public final void suspend( );  
}

					  


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint