NIO SocketChannel send guarantees
Krajcsovszki, Gergely
Gergely.Krajcsovszki at morganstanley.com
Wed Apr 6 13:54:36 UTC 2016
Hi Team,
We are using NIO SocketChannels to exchange data over TCP. A colleague noticed that if he writes a lot of data to the socket channel, closes it, then immediately exits the application (either via System.exit() or just letting the main() method return) sometimes some of the data is not sent, even if he flushes before closing. After adding a wait loop until the underlying socket's isOutputShutdown() and isClosed() methods return true the problem went away.
This got us thinking, what are the guarantees of NIO? What could happen to the already written data if
1. The application terminates
2. The JVM crashes
3. The OS crashes
after
1. socketChannel.write(...)
2. socketChannel.close() (following multiple writes)
returns?
Can the settings influence this somehow?
We are using various versions of Oracle JDK 7 and 8, all we tried seem to exhibit the same behavior. We've only tried it on Windows 7 64bit, but Linux behavior (if different) is perhaps even more interesting to us.
Thank you very much for your help,
Gergely Krajcsovszki
________________________________
NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies; do not disclose, use or act upon the information; and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20160406/5ec3eb3f/attachment-0001.html>
More information about the nio-dev
mailing list