RFR for JDK-8027212: java/nio/channels/Selector/SelectAfterRead.java fails intermittently
Eric Wang
yiming.wang at oracle.com
Mon Nov 18 22:25:02 PST 2013
Hi everyone,
I'm working on the bug https://bugs.openjdk.java.net/browse/JDK-8027212.
after research, it is a test failure.
Root Cause:
The test is based on bad assumption that the ByteServer thread has
finished to write bytes to client before the client SelectAfterRead
calls selector.select(TIMEOUT)(TIMEOUT=1000).
Suggested Fix:
Use CountDownLatch to sync up server and client, The fix looks like
below, Please let me know if you have any comments or suggestions.
server side:
class ByteServer {
*CountDownLatch latch = new CountDownLatch(1);*
public void start() {
serverthread = new Thread() {
public void run() {
try {...
} finally { *latch.countDown();*}*// count down when
thread finish to write bytes*
}
};
serverThread.start();
}
* public void await() {**latch.await();**}* *// new api for sync up**
*}
client side:
class SelectAfterRead {
public static void main(String[] args) {
...
* server.await(); // sync up with server**
* if (sel.select(TIMEOUT) != 1)
...
}
}
Thanks.
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20131119/78068d4e/attachment.html
More information about the nio-dev
mailing list