7013961: Threads attached via JNI attach prevent daemon ThreadGroups from being destroyed
authorchegar
Wed, 09 Feb 2011 09:53:07 +0000
changeset 8192 f0ee3e38944a
parent 8190 c8cdf811a171
child 8194 09cff98c5bb8
7013961: Threads attached via JNI attach prevent daemon ThreadGroups from being destroyed Reviewed-by: dholmes
jdk/src/share/classes/java/lang/Thread.java
jdk/src/share/classes/java/lang/ThreadGroup.java
--- a/jdk/src/share/classes/java/lang/Thread.java	Tue Feb 08 13:30:30 2011 -0800
+++ b/jdk/src/share/classes/java/lang/Thread.java	Wed Feb 09 09:53:07 2011 +0000
@@ -690,7 +690,7 @@
         /* Notify the group that this thread is about to be started
          * so that it can be added to the group's list of threads
          * and the group's unstarted count can be decremented. */
-        group.threadStarting(this);
+        group.add(this);
 
         boolean started = false;
         try {
--- a/jdk/src/share/classes/java/lang/ThreadGroup.java	Tue Feb 08 13:30:30 2011 -0800
+++ b/jdk/src/share/classes/java/lang/ThreadGroup.java	Wed Feb 09 09:53:07 2011 +0000
@@ -868,21 +868,6 @@
     }
 
     /**
-     * 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
@@ -910,6 +895,12 @@
             // This is done last so it doesn't matter in case the
             // thread is killed
             nthreads++;
+
+            // The thread is now a fully fledged member of the group, even
+            // though it may, or may not, have been started yet. It will prevent
+            // the group from being destroyed so the unstarted Threads count is
+            // decremented.
+            nUnstartedThreads--;
         }
     }