Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/classes/java/lang/ThreadGroup.java
          +++ new/src/share/classes/java/lang/ThreadGroup.java
↓ open down ↓ 862 lines elided ↑ open up ↑
 863  863              if (destroyed) {
 864  864                  throw new IllegalThreadStateException();
 865  865              }
 866  866              nUnstartedThreads++;
 867  867          }
 868  868      }
 869  869  
 870  870      /**
 871  871       * Notifies the group that the thread {@code t} is about to be
 872  872       * started and adds the thread to this thread group.
      873 +     * 
      874 +     * The thread is now a fully fledged member of the group, even though
      875 +     * it hasn't been started yet. It will prevent the group from being
      876 +     * destroyed so the unstarted Threads count is decremented.
 873  877       */
 874  878      void threadStarting(Thread t) {
 875      -        add(t);
      879 +        synchronized (this) {
      880 +            add(t);
      881 +            nUnstartedThreads--;
      882 +        }
 876  883      }
 877  884  
 878  885      /**
 879  886       * Adds the specified thread to this thread group.
 880  887       *
 881  888       * <p> Note: This method is called from both library code
 882  889       * and the Virtual Machine. It is called from VM to add
 883  890       * certain system threads to the system thread group.
 884  891       *
 885  892       * @param  t
↓ open down ↓ 14 lines elided ↑ open up ↑
 900  907              }
 901  908              threads[nthreads] = t;
 902  909  
 903  910              // This is done last so it doesn't matter in case the
 904  911              // thread is killed
 905  912              nthreads++;
 906  913          }
 907  914      }
 908  915  
 909  916      /**
 910      -     * Notifies the group that the thread {@code t} has completed
      917 +     * Notifies the group that the thread {@code t} has failed
 911  918       * an attempt to start.
 912  919       *
 913      -     * <p> If the thread has been started successfully
 914      -     * then the group has its unstarted Threads count decremented.
 915      -     * Otherwise the state of this thread group is rolled back as if the
      920 +     * <p> The state of this thread group is rolled back as if the
 916  921       * attempt to start the thread has never occurred. The thread is again
 917  922       * considered an unstarted member of the thread group, and a subsequent
 918  923       * attempt to start the thread is permitted.
 919  924       *
 920  925       * @param  t
 921  926       *         the Thread whose start method was invoked
 922  927       *
 923  928       * @param  failed
 924  929       *         true if the thread could not be started successfully
 925  930       */
 926      -    void threadStarted(Thread t, boolean failed) {
      931 +    void threadStartFailed(Thread t) {
 927  932          synchronized(this) {
 928      -            if (failed) {
 929      -                remove(t);
 930      -            } else {
 931      -                if (destroyed) {
 932      -                    return;
 933      -                }
 934      -                nUnstartedThreads--;
 935      -            }
      933 +            remove(t);
      934 +            nUnstartedThreads++;
 936  935          }
 937  936      }
 938  937  
 939  938      /**
 940  939       * Notifies the group that the thread {@code t} has terminated.
 941  940       *
 942  941       * <p> Destroy the group if all of the following conditions are
 943  942       * true: this is a daemon thread group; there are no more alive
 944  943       * or unstarted threads in the group; there are no subgroups in
 945  944       * this thread group.
↓ open down ↓ 159 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX