8004183: test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java doesn't clean-up
authorallwin
Fri, 17 Jan 2014 16:25:17 +0100
changeset 22296 be5ab806f457
parent 22295 f140aab86aed
child 22297 1c62c67d9dd2
8004183: test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java doesn't clean-up Reviewed-by: sjiang, dfuchs, dholmes, olagneau, dholmes, jbachorik
jdk/test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java
--- a/jdk/test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java	Fri Jan 17 15:58:18 2014 +0100
+++ b/jdk/test/sun/management/jmxremote/LocalRMIServerSocketFactoryTest.java	Fri Jan 17 16:25:17 2014 +0100
@@ -44,6 +44,7 @@
 
     private static final SynchronousQueue<Exception> queue =
             new SynchronousQueue<Exception>();
+    private static volatile boolean isRunning = true;
 
     static final class Result extends Exception {
 
@@ -91,19 +92,23 @@
         Thread t = new Thread() {
 
             public void run() {
-                while (true) {
+                while (isRunning) {
                     Exception error = Result.SUCCESS;
                     try {
                         System.err.println("Accepting: ");
                         final Socket ss = s.accept();
                         System.err.println(ss.getInetAddress() + " accepted");
                     } catch (Exception x) {
-                        x.printStackTrace();
+                        if (isRunning) {
+                            x.printStackTrace();
+                        }
                         error = x;
                     } finally {
                         try {
-                            // wait for the client to get the exception.
-                            queue.put(error);
+                            if (isRunning) {
+                                // wait for the client to get the exception.
+                                queue.put(error);
+                            }
                         } catch (Exception x) {
                             // too bad!
                             System.err.println("Could't send result to client!");
@@ -114,32 +119,38 @@
                 }
             }
         };
-        t.setDaemon(true);
-        t.start();
+
+        try {
+            t.start();
 
-        System.err.println("new Socket((String)null, port)");
-        final Socket s1 = new Socket((String) null, port);
-        checkError("new Socket((String)null, port)");
-        s1.close();
-        System.err.println("new Socket((String)null, port): PASSED");
+            System.err.println("new Socket((String)null, port)");
+            final Socket s1 = new Socket((String) null, port);
+            checkError("new Socket((String)null, port)");
+            s1.close();
+            System.err.println("new Socket((String)null, port): PASSED");
+
+            System.err.println("new Socket(InetAddress.getByName(null), port)");
+            final Socket s2 = new Socket(InetAddress.getByName(null), port);
+            checkError("new Socket(InetAddress.getByName(null), port)");
+            s2.close();
+            System.err.println("new Socket(InetAddress.getByName(null), port): PASSED");
 
-        System.err.println("new Socket(InetAddress.getByName(null), port)");
-        final Socket s2 = new Socket(InetAddress.getByName(null), port);
-        checkError("new Socket(InetAddress.getByName(null), port)");
-        s2.close();
-        System.err.println("new Socket(InetAddress.getByName(null), port): PASSED");
+            System.err.println("new Socket(localhost, port)");
+            final Socket s3 = new Socket("localhost", port);
+            checkError("new Socket(localhost, port)");
+            s3.close();
+            System.err.println("new Socket(localhost, port): PASSED");
 
-        System.err.println("new Socket(localhost, port)");
-        final Socket s3 = new Socket("localhost", port);
-        checkError("new Socket(localhost, port)");
-        s3.close();
-        System.err.println("new Socket(localhost, port): PASSED");
-
-        System.err.println("new Socket(127.0.0.1, port)");
-        final Socket s4 = new Socket("127.0.0.1", port);
-        checkError("new Socket(127.0.0.1, port)");
-        s4.close();
-        System.err.println("new Socket(127.0.0.1, port): PASSED");
-
+            System.err.println("new Socket(127.0.0.1, port)");
+            final Socket s4 = new Socket("127.0.0.1", port);
+            checkError("new Socket(127.0.0.1, port)");
+            s4.close();
+            System.err.println("new Socket(127.0.0.1, port): PASSED");
+        }
+        finally {
+            isRunning = false;
+            s.close();
+            t.join();
+        }
     }
 }