8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test
authorxiaofeya
Tue, 27 Sep 2016 01:36:31 -0700
changeset 41136 44ba1622deee
parent 41135 01650fdf3284
child 41137 cbc639238d91
8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test Reviewed-by: chegar
jdk/test/java/net/ServerSocket/ThreadStop.java
--- a/jdk/test/java/net/ServerSocket/ThreadStop.java	Mon Sep 26 13:37:10 2016 -0700
+++ b/jdk/test/java/net/ServerSocket/ThreadStop.java	Tue Sep 27 01:36:31 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -68,23 +68,23 @@
         thr.start();
 
         // give server time to block in ServerSocket.accept()
-        Thread.currentThread().sleep(2000);
+        Thread.sleep(2000);
 
         // "stop" the thread
         thr.stop();
 
         // give thread time to stop
-        Thread.currentThread().sleep(2000);
+        Thread.sleep(2000);
 
         // it's platform specific if Thread.stop interrupts the
         // thread - on Linux/Windows most likely that thread is
         // still in accept() so we connect to server which causes
         // it to unblock and do JNI-stuff with a pending exception
 
-        try {
-            Socket s = new Socket("localhost", svr.localPort());
-        } catch (IOException ioe) { }
-
+        try (Socket s = new Socket("localhost", svr.localPort())) {
+        } catch (IOException ioe) {
+        }
+        thr.join();
     }
 
 }