8190324: ThreadPoolExecutor should not specify a dependency on finalization
authordl
Sat, 10 Feb 2018 09:17:53 -0800
changeset 48842 a5a2e4770524
parent 48841 0937e5f799df
child 48843 21efc1774302
8190324: ThreadPoolExecutor should not specify a dependency on finalization Reviewed-by: martin, psandoz, alanb, rriggs, dholmes
src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java
test/jdk/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java
--- a/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java	Sat Feb 10 07:06:16 2018 -0500
+++ b/src/java.base/share/classes/java/util/concurrent/ThreadPoolExecutor.java	Sat Feb 10 09:17:53 2018 -0800
@@ -35,9 +35,6 @@
 
 package java.util.concurrent;
 
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.ConcurrentModificationException;
 import java.util.HashSet;
@@ -268,8 +265,8 @@
  *
  * <dd>A pool that is no longer referenced in a program <em>AND</em>
  * has no remaining threads may be reclaimed (garbage collected)
- * without being explicity shutdown. You can configure a pool to allow
- * all unused threads to eventually die by setting appropriate
+ * without being explicitly shutdown. You can configure a pool to
+ * allow all unused threads to eventually die by setting appropriate
  * keep-alive times, using a lower bound of zero core threads and/or
  * setting {@link #allowCoreThreadTimeOut(boolean)}.  </dd>
  *
@@ -1462,6 +1459,18 @@
         }
     }
 
+    // Override without "throws Throwable" for compatibility with subclasses
+    // whose finalize method invokes super.finalize() (as is recommended).
+    // Before JDK 11, finalize() had a non-empty method body.
+
+    /**
+     * @implNote Previous versions of this class had a finalize method
+     * that shut down this executor, but in this version, finalize
+     * does nothing.
+     */
+    @Deprecated(since="9")
+    protected void finalize() {}
+
     /**
      * Sets the thread factory used to create new threads.
      *
--- a/test/jdk/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java	Sat Feb 10 07:06:16 2018 -0500
+++ b/test/jdk/java/util/concurrent/tck/ThreadPoolExecutorSubclassTest.java	Sat Feb 10 09:17:53 2018 -0800
@@ -1994,4 +1994,19 @@
         }
     }
 
+    public void testFinalizeMethodCallsSuperFinalize() {
+        new CustomTPE(1, 1,
+                      LONG_DELAY_MS, MILLISECONDS,
+                      new LinkedBlockingQueue<Runnable>()) {
+
+            /**
+             * A finalize method without "throws Throwable", that
+             * calls super.finalize().
+             */
+            protected void finalize() {
+                super.finalize();
+            }
+        }.shutdown();
+    }
+
 }