Removed the daemon-threads-based ExecutorService JDK-8210696-branch
authorprappo
Wed, 01 May 2019 15:10:09 +0100
branchJDK-8210696-branch
changeset 57346 3efc6cb7ffdb
parent 57345 ff884a2f247b
child 57351 b9e5f8090688
Removed the daemon-threads-based ExecutorService
test/jdk/com/sun/jndi/ldap/RemoveNamingListenerTest.java
test/jdk/com/sun/jndi/ldap/lib/BaseLdapServer.java
--- a/test/jdk/com/sun/jndi/ldap/RemoveNamingListenerTest.java	Wed May 01 00:06:22 2019 -0700
+++ b/test/jdk/com/sun/jndi/ldap/RemoveNamingListenerTest.java	Wed May 01 15:10:09 2019 +0100
@@ -134,7 +134,7 @@
     private byte[] searchResponse = {0x30, 0x0C, 0x02, 0x01, 0x02, 0x65, 0x07, 0x0A, 0x01, 0x00, 0x04, 0x00, 0x04, 0x00};
 
     public TestLDAPServer() throws IOException {
-        super(new ServerSocket(0, 0, InetAddress.getLoopbackAddress()), true);
+        super(new ServerSocket(0, 0, InetAddress.getLoopbackAddress()));
         setCommonRequestHandler((msg, out) -> {
             switch (msg.getOperation()) {
                 case BIND_REQUEST:
--- a/test/jdk/com/sun/jndi/ldap/lib/BaseLdapServer.java	Wed May 01 00:06:22 2019 -0700
+++ b/test/jdk/com/sun/jndi/ldap/lib/BaseLdapServer.java	Wed May 01 15:10:09 2019 +0100
@@ -92,7 +92,6 @@
     private ExecutorService workingPool;
     private ConnectionHandler connectionHandler;
     private SessionHandler sessionHandler;
-    private boolean useDaemonThread = false;
 
     enum DebugLevel {
         FULL,      // all debug message will be printed
@@ -114,30 +113,14 @@
     }
 
     /**
-     * BaseLdapServer overload constructor with given server socket.
-     *
-     * @param serverSocket given server socket
-     */
-    public BaseLdapServer(ServerSocket serverSocket) {
-        this(serverSocket, false);
-    }
-
-    /**
      * BaseLdapServer constructor with given server socket and specify whether
      * use daemon for each accept connection handling thread.
      *
      * @param serverSocket    given server socket
-     * @param useDaemonThread <tt>true</tt> if use daemon thread
      */
-    public BaseLdapServer(ServerSocket serverSocket, boolean useDaemonThread) {
+    public BaseLdapServer(ServerSocket serverSocket) {
         this.serverSocket = Objects.requireNonNull(serverSocket);
-        this.useDaemonThread = useDaemonThread;
-        if (useDaemonThread) {
-            workingPool = Executors
-                    .newCachedThreadPool(new DefaultDaemonThreadFactory());
-        } else {
-            workingPool = Executors.newCachedThreadPool();
-        }
+        workingPool = Executors.newCachedThreadPool();
         try {
             stackWalker = StackWalker.getInstance(RETAIN_CLASS_REFERENCE);
         } catch (SecurityException se) {
@@ -201,19 +184,17 @@
         isRunning = false;
         workingPool.shutdown();
         cleanupClosableRes(serverSocket);
-        if (!useDaemonThread) {
-            // let's cleanup thread pool
-            synchronized (socketList) {
-                socketList.forEach(BaseLdapServer::cleanupClosableRes);
+        // let's cleanup thread pool
+        synchronized (socketList) {
+            socketList.forEach(BaseLdapServer::cleanupClosableRes);
+        }
+        try {
+            if (!workingPool.awaitTermination(10, TimeUnit.SECONDS)) {
+                workingPool.shutdownNow();
             }
-            try {
-                if (!workingPool.awaitTermination(10, TimeUnit.SECONDS)) {
-                    workingPool.shutdownNow();
-                }
-            } catch (InterruptedException e) {
-                workingPool.shutdownNow();
-                Thread.currentThread().interrupt();
-            }
+        } catch (InterruptedException e) {
+            workingPool.shutdownNow();
+            Thread.currentThread().interrupt();
         }
     }
 
@@ -382,19 +363,6 @@
         }
     }
 
-    class DefaultDaemonThreadFactory implements ThreadFactory {
-
-        private ThreadFactory defaultThreadFactory = Executors
-                .defaultThreadFactory();
-
-        @Override
-        public Thread newThread(Runnable r) {
-            Thread thread = defaultThreadFactory.newThread(r);
-            thread.setDaemon(true);
-            return thread;
-        }
-    }
-
     /**
      * Default connection handler implementation.
      */