src/share/classes/java/lang/ThreadGroup.java

Print this page




 653     /**
 654      * Suspends all threads in this thread group.
 655      * <p>
 656      * First, the <code>checkAccess</code> method of this thread group is
 657      * called with no arguments; this may result in a security exception.
 658      * <p>
 659      * This method then calls the <code>suspend</code> method on all the
 660      * threads in this thread group and in all of its subgroups.
 661      *
 662      * @exception  SecurityException  if the current thread is not allowed
 663      *               to access this thread group or any of the threads in
 664      *               the thread group.
 665      * @see        java.lang.Thread#suspend()
 666      * @see        java.lang.SecurityException
 667      * @see        java.lang.ThreadGroup#checkAccess()
 668      * @since      JDK1.0
 669      * @deprecated    This method is inherently deadlock-prone.  See
 670      *     {@link Thread#suspend} for details.
 671      */
 672     @Deprecated

 673     public final void suspend() {
 674         if (stopOrSuspend(true))
 675             Thread.currentThread().suspend();
 676     }
 677 
 678     /**
 679      * Helper method: recursively stops or suspends (as directed by the
 680      * boolean argument) all of the threads in this thread group and its
 681      * subgroups, except the current thread.  This method returns true
 682      * if (and only if) the current thread is found to be in this thread
 683      * group or one of its subgroups.
 684      */

 685     private boolean stopOrSuspend(boolean suspend) {
 686         boolean suicide = false;
 687         Thread us = Thread.currentThread();
 688         int ngroupsSnapshot;
 689         ThreadGroup[] groupsSnapshot = null;
 690         synchronized (this) {
 691             checkAccess();
 692             for (int i = 0 ; i < nthreads ; i++) {
 693                 if (threads[i]==us)
 694                     suicide = true;
 695                 else if (suspend)
 696                     threads[i].suspend();
 697                 else
 698                     threads[i].stop();
 699             }
 700 
 701             ngroupsSnapshot = ngroups;
 702             if (groups != null) {
 703                 groupsSnapshot = Arrays.copyOf(groups, ngroupsSnapshot);
 704             }


 714      * <p>
 715      * First, the <code>checkAccess</code> method of this thread group is
 716      * called with no arguments; this may result in a security exception.
 717      * <p>
 718      * This method then calls the <code>resume</code> method on all the
 719      * threads in this thread group and in all of its sub groups.
 720      *
 721      * @exception  SecurityException  if the current thread is not allowed to
 722      *               access this thread group or any of the threads in the
 723      *               thread group.
 724      * @see        java.lang.SecurityException
 725      * @see        java.lang.Thread#resume()
 726      * @see        java.lang.ThreadGroup#checkAccess()
 727      * @since      JDK1.0
 728      * @deprecated    This method is used solely in conjunction with
 729      *      <tt>Thread.suspend</tt> and <tt>ThreadGroup.suspend</tt>,
 730      *       both of which have been deprecated, as they are inherently
 731      *       deadlock-prone.  See {@link Thread#suspend} for details.
 732      */
 733     @Deprecated

 734     public final void resume() {
 735         int ngroupsSnapshot;
 736         ThreadGroup[] groupsSnapshot;
 737         synchronized (this) {
 738             checkAccess();
 739             for (int i = 0 ; i < nthreads ; i++) {
 740                 threads[i].resume();
 741             }
 742             ngroupsSnapshot = ngroups;
 743             if (groups != null) {
 744                 groupsSnapshot = Arrays.copyOf(groups, ngroupsSnapshot);
 745             } else {
 746                 groupsSnapshot = null;
 747             }
 748         }
 749         for (int i = 0 ; i < ngroupsSnapshot ; i++) {
 750             groupsSnapshot[i].resume();
 751         }
 752     }
 753 




 653     /**
 654      * Suspends all threads in this thread group.
 655      * <p>
 656      * First, the <code>checkAccess</code> method of this thread group is
 657      * called with no arguments; this may result in a security exception.
 658      * <p>
 659      * This method then calls the <code>suspend</code> method on all the
 660      * threads in this thread group and in all of its subgroups.
 661      *
 662      * @exception  SecurityException  if the current thread is not allowed
 663      *               to access this thread group or any of the threads in
 664      *               the thread group.
 665      * @see        java.lang.Thread#suspend()
 666      * @see        java.lang.SecurityException
 667      * @see        java.lang.ThreadGroup#checkAccess()
 668      * @since      JDK1.0
 669      * @deprecated    This method is inherently deadlock-prone.  See
 670      *     {@link Thread#suspend} for details.
 671      */
 672     @Deprecated
 673     @SuppressWarnings("deprecation")
 674     public final void suspend() {
 675         if (stopOrSuspend(true))
 676             Thread.currentThread().suspend();
 677     }
 678 
 679     /**
 680      * Helper method: recursively stops or suspends (as directed by the
 681      * boolean argument) all of the threads in this thread group and its
 682      * subgroups, except the current thread.  This method returns true
 683      * if (and only if) the current thread is found to be in this thread
 684      * group or one of its subgroups.
 685      */
 686     @SuppressWarnings("deprecation")
 687     private boolean stopOrSuspend(boolean suspend) {
 688         boolean suicide = false;
 689         Thread us = Thread.currentThread();
 690         int ngroupsSnapshot;
 691         ThreadGroup[] groupsSnapshot = null;
 692         synchronized (this) {
 693             checkAccess();
 694             for (int i = 0 ; i < nthreads ; i++) {
 695                 if (threads[i]==us)
 696                     suicide = true;
 697                 else if (suspend)
 698                     threads[i].suspend();
 699                 else
 700                     threads[i].stop();
 701             }
 702 
 703             ngroupsSnapshot = ngroups;
 704             if (groups != null) {
 705                 groupsSnapshot = Arrays.copyOf(groups, ngroupsSnapshot);
 706             }


 716      * <p>
 717      * First, the <code>checkAccess</code> method of this thread group is
 718      * called with no arguments; this may result in a security exception.
 719      * <p>
 720      * This method then calls the <code>resume</code> method on all the
 721      * threads in this thread group and in all of its sub groups.
 722      *
 723      * @exception  SecurityException  if the current thread is not allowed to
 724      *               access this thread group or any of the threads in the
 725      *               thread group.
 726      * @see        java.lang.SecurityException
 727      * @see        java.lang.Thread#resume()
 728      * @see        java.lang.ThreadGroup#checkAccess()
 729      * @since      JDK1.0
 730      * @deprecated    This method is used solely in conjunction with
 731      *      <tt>Thread.suspend</tt> and <tt>ThreadGroup.suspend</tt>,
 732      *       both of which have been deprecated, as they are inherently
 733      *       deadlock-prone.  See {@link Thread#suspend} for details.
 734      */
 735     @Deprecated
 736     @SuppressWarnings("deprecation")
 737     public final void resume() {
 738         int ngroupsSnapshot;
 739         ThreadGroup[] groupsSnapshot;
 740         synchronized (this) {
 741             checkAccess();
 742             for (int i = 0 ; i < nthreads ; i++) {
 743                 threads[i].resume();
 744             }
 745             ngroupsSnapshot = ngroups;
 746             if (groups != null) {
 747                 groupsSnapshot = Arrays.copyOf(groups, ngroupsSnapshot);
 748             } else {
 749                 groupsSnapshot = null;
 750             }
 751         }
 752         for (int i = 0 ; i < ngroupsSnapshot ; i++) {
 753             groupsSnapshot[i].resume();
 754         }
 755     }
 756