changeset 15726:b2e7ba45d2de

8154525: java/net/ServerSocket/ThreadStop.java fails intermittently with error while cleaning up threads after test Reviewed-by: chegar
author xiaofeya
date Tue, 27 Sep 2016 01:36:31 -0700
parents 57746f6885ac
children 665096863382
files test/java/net/ServerSocket/ThreadStop.java
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/net/ServerSocket/ThreadStop.java	Mon Sep 26 13:37:10 2016 -0700
+++ b/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();
     }
 
 }