8141595: (so) java/nio/channels/ServerSocketChannel/NonBlockingAccept.java fails intermittently
authoralanb
Fri, 15 Jan 2016 11:09:25 +0000
changeset 34966 03a7b2386cef
parent 34965 38232541c49a
child 34967 5921e8a0ff14
8141595: (so) java/nio/channels/ServerSocketChannel/NonBlockingAccept.java fails intermittently Reviewed-by: alanb Contributed-by: huaming.li@oracle.com
jdk/test/java/nio/channels/ServerSocketChannel/NonBlockingAccept.java
--- a/jdk/test/java/nio/channels/ServerSocketChannel/NonBlockingAccept.java	Fri Jan 15 10:58:09 2016 +0000
+++ b/jdk/test/java/nio/channels/ServerSocketChannel/NonBlockingAccept.java	Fri Jan 15 11:09:25 2016 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 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
@@ -22,7 +22,7 @@
  */
 
 /* @test
- * @bug 4801882 5046333
+ * @bug 4801882 5046333 8141595
  * @summary test ServerSocketAdaptor.accept on nonblocking channel
  * @library ..
  * @build TestUtil
@@ -57,8 +57,17 @@
         SocketChannel sc = SocketChannel.open();
         sc.configureBlocking(false);
         sc.connect(isa);
-        Thread.sleep(100);
-        ss.accept();
+
+        // loop until accepted
+        while (true) {
+            try {
+                ss.accept();
+                break;
+            } catch (IllegalBlockingModeException ex) {
+                System.out.println(ex + ", sleeping ...");
+                Thread.sleep(100);
+            }
+        }
 
     }