590
591 /**
592 * Stops all threads in this thread group.
593 * <p>
594 * First, the <code>checkAccess</code> method of this thread group is
595 * called with no arguments; this may result in a security exception.
596 * <p>
597 * This method then calls the <code>stop</code> method on all the
598 * threads in this thread group and in all of its subgroups.
599 *
600 * @exception SecurityException if the current thread is not allowed
601 * to access this thread group or any of the threads in
602 * the thread group.
603 * @see java.lang.SecurityException
604 * @see java.lang.Thread#stop()
605 * @see java.lang.ThreadGroup#checkAccess()
606 * @since 1.0
607 * @deprecated This method is inherently unsafe. See
608 * {@link Thread#stop} for details.
609 */
610 @Deprecated
611 public final void stop() {
612 if (stopOrSuspend(false))
613 Thread.currentThread().stop();
614 }
615
616 /**
617 * Interrupts all threads in this thread group.
618 * <p>
619 * First, the <code>checkAccess</code> method of this thread group is
620 * called with no arguments; this may result in a security exception.
621 * <p>
622 * This method then calls the <code>interrupt</code> method on all the
623 * threads in this thread group and in all of its subgroups.
624 *
625 * @exception SecurityException if the current thread is not allowed
626 * to access this thread group or any of the threads in
627 * the thread group.
628 * @see java.lang.Thread#interrupt()
629 * @see java.lang.SecurityException
630 * @see java.lang.ThreadGroup#checkAccess()
652
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 1.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) {
715 * Resumes all threads in this thread group.
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 1.0
730 * @deprecated This method is used solely in conjunction with
731 * {@code Thread.suspend} and {@code ThreadGroup.suspend},
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 }
1056 if (ueh != null) {
1057 ueh.uncaughtException(t, e);
1058 } else if (!(e instanceof ThreadDeath)) {
1059 System.err.print("Exception in thread \""
1060 + t.getName() + "\" ");
1061 e.printStackTrace(System.err);
1062 }
1063 }
1064 }
1065
1066 /**
1067 * Used by VM to control lowmem implicit suspension.
1068 *
1069 * @param b boolean to allow or disallow suspension
1070 * @return true on success
1071 * @since 1.1
1072 * @deprecated The definition of this call depends on {@link #suspend},
1073 * which is deprecated. Further, the behavior of this call
1074 * was never specified.
1075 */
1076 @Deprecated
1077 public boolean allowThreadSuspension(boolean b) {
1078 this.vmAllowSuspension = b;
1079 if (!b) {
1080 VM.unsuspendSomeThreads();
1081 }
1082 return true;
1083 }
1084
1085 /**
1086 * Returns a string representation of this Thread group.
1087 *
1088 * @return a string representation of this thread group.
1089 * @since 1.0
1090 */
1091 public String toString() {
1092 return getClass().getName() + "[name=" + getName() + ",maxpri=" + maxPriority + "]";
1093 }
1094 }
|
590
591 /**
592 * Stops all threads in this thread group.
593 * <p>
594 * First, the <code>checkAccess</code> method of this thread group is
595 * called with no arguments; this may result in a security exception.
596 * <p>
597 * This method then calls the <code>stop</code> method on all the
598 * threads in this thread group and in all of its subgroups.
599 *
600 * @exception SecurityException if the current thread is not allowed
601 * to access this thread group or any of the threads in
602 * the thread group.
603 * @see java.lang.SecurityException
604 * @see java.lang.Thread#stop()
605 * @see java.lang.ThreadGroup#checkAccess()
606 * @since 1.0
607 * @deprecated This method is inherently unsafe. See
608 * {@link Thread#stop} for details.
609 */
610 @Deprecated(since="1.2")
611 public final void stop() {
612 if (stopOrSuspend(false))
613 Thread.currentThread().stop();
614 }
615
616 /**
617 * Interrupts all threads in this thread group.
618 * <p>
619 * First, the <code>checkAccess</code> method of this thread group is
620 * called with no arguments; this may result in a security exception.
621 * <p>
622 * This method then calls the <code>interrupt</code> method on all the
623 * threads in this thread group and in all of its subgroups.
624 *
625 * @exception SecurityException if the current thread is not allowed
626 * to access this thread group or any of the threads in
627 * the thread group.
628 * @see java.lang.Thread#interrupt()
629 * @see java.lang.SecurityException
630 * @see java.lang.ThreadGroup#checkAccess()
652
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 1.0
669 * @deprecated This method is inherently deadlock-prone. See
670 * {@link Thread#suspend} for details.
671 */
672 @Deprecated(since="1.2")
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) {
715 * Resumes all threads in this thread group.
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 1.0
730 * @deprecated This method is used solely in conjunction with
731 * {@code Thread.suspend} and {@code ThreadGroup.suspend},
732 * both of which have been deprecated, as they are inherently
733 * deadlock-prone. See {@link Thread#suspend} for details.
734 */
735 @Deprecated(since="1.2")
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 }
1056 if (ueh != null) {
1057 ueh.uncaughtException(t, e);
1058 } else if (!(e instanceof ThreadDeath)) {
1059 System.err.print("Exception in thread \""
1060 + t.getName() + "\" ");
1061 e.printStackTrace(System.err);
1062 }
1063 }
1064 }
1065
1066 /**
1067 * Used by VM to control lowmem implicit suspension.
1068 *
1069 * @param b boolean to allow or disallow suspension
1070 * @return true on success
1071 * @since 1.1
1072 * @deprecated The definition of this call depends on {@link #suspend},
1073 * which is deprecated. Further, the behavior of this call
1074 * was never specified.
1075 */
1076 @Deprecated(since="1.2")
1077 public boolean allowThreadSuspension(boolean b) {
1078 this.vmAllowSuspension = b;
1079 if (!b) {
1080 VM.unsuspendSomeThreads();
1081 }
1082 return true;
1083 }
1084
1085 /**
1086 * Returns a string representation of this Thread group.
1087 *
1088 * @return a string representation of this thread group.
1089 * @since 1.0
1090 */
1091 public String toString() {
1092 return getClass().getName() + "[name=" + getName() + ",maxpri=" + maxPriority + "]";
1093 }
1094 }
|