提交 11007a14 编写于 作者: M michaelm

8196775: java/net/Socket/asyncClose/Race.java failed intermittently on Windows...

8196775: java/net/Socket/asyncClose/Race.java failed intermittently on Windows with ConnectException: Connection refused
Reviewed-by: dfuchs
上级 772531d1
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
import java.io.InputStream; import java.io.InputStream;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.ConnectException;
import java.net.SocketException; import java.net.SocketException;
import java.util.concurrent.Phaser; import java.util.concurrent.Phaser;
...@@ -43,33 +44,37 @@ public class Race { ...@@ -43,33 +44,37 @@ public class Race {
final int port = ss.getLocalPort(); final int port = ss.getLocalPort();
final Phaser phaser = new Phaser(THREADS + 1); final Phaser phaser = new Phaser(THREADS + 1);
for (int i=0; i<100; i++) { for (int i=0; i<100; i++) {
final Socket s = new Socket("localhost", port); try {
s.setSoLinger(false, 0); final Socket s = new Socket("localhost", port);
try (Socket sa = ss.accept()) { s.setSoLinger(false, 0);
sa.setSoLinger(false, 0); try (Socket sa = ss.accept()) {
final InputStream is = s.getInputStream(); sa.setSoLinger(false, 0);
Thread[] threads = new Thread[THREADS]; final InputStream is = s.getInputStream();
for (int j=0; j<THREADS; j++) { Thread[] threads = new Thread[THREADS];
threads[j] = new Thread() { for (int j=0; j<THREADS; j++) {
public void run() { threads[j] = new Thread() {
try { public void run() {
phaser.arriveAndAwaitAdvance(); try {
while (is.read() != -1) phaser.arriveAndAwaitAdvance();
Thread.sleep(50); while (is.read() != -1)
} catch (Exception x) { Thread.sleep(50);
if (!(x instanceof SocketException } catch (Exception x) {
&& x.getMessage().equalsIgnoreCase("socket closed"))) if (!(x instanceof SocketException
x.printStackTrace(); && x.getMessage().equalsIgnoreCase("socket closed")))
// ok, expect Socket closed x.printStackTrace();
} // ok, expect Socket closed
}}; }
}};
}
for (int j=0; j<100; j++)
threads[j].start();
phaser.arriveAndAwaitAdvance();
s.close();
for (int j=0; j<100; j++)
threads[j].join();
} }
for (int j=0; j<100; j++) } catch (ConnectException e) {
threads[j].start(); System.err.println("Exception " + e + " Port: " + port);
phaser.arriveAndAwaitAdvance();
s.close();
for (int j=0; j<100; j++)
threads[j].join();
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册