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

Print this page

        

@@ -868,14 +868,21 @@
     }
 
     /**
      * Notifies the group that the thread {@code t} is about to be
      * started and adds the thread to this thread group.
+     * 
+     * The thread is now a fully fledged member of the group, even though
+     * it hasn't been started yet. It will prevent the group from being
+     * destroyed so the unstarted Threads count is decremented.
      */
     void threadStarting(Thread t) {
+        synchronized (this) {
         add(t);
+            nUnstartedThreads--;
     }
+    }
 
     /**
      * Adds the specified thread to this thread group.
      *
      * <p> Note: This method is called from both library code

@@ -905,16 +912,14 @@
             nthreads++;
         }
     }
 
     /**
-     * Notifies the group that the thread {@code t} has completed
+     * Notifies the group that the thread {@code t} has failed
      * an attempt to start.
      *
-     * <p> If the thread has been started successfully
-     * then the group has its unstarted Threads count decremented.
-     * Otherwise the state of this thread group is rolled back as if the
+     * <p> The state of this thread group is rolled back as if the
      * attempt to start the thread has never occurred. The thread is again
      * considered an unstarted member of the thread group, and a subsequent
      * attempt to start the thread is permitted.
      *
      * @param  t

@@ -921,22 +926,16 @@
      *         the Thread whose start method was invoked
      *
      * @param  failed
      *         true if the thread could not be started successfully
      */
-    void threadStarted(Thread t, boolean failed) {
+    void threadStartFailed(Thread t) {
         synchronized(this) {
-            if (failed) {
                 remove(t);
-            } else {
-                if (destroyed) {
-                    return;
+            nUnstartedThreads++;
                 }
-                nUnstartedThreads--;
             }
-        }
-    }
 
     /**
      * Notifies the group that the thread {@code t} has terminated.
      *
      * <p> Destroy the group if all of the following conditions are