Closing in non-blocking mode does not block.
You can put the channel into lock mode, set a positive delay timeout and close it, and it would block until the delay timeout when the socket send buffer was empty, but, alas, Java does not throw an exception if the delay timeout expires, therefore, you cannot know if all the data has passed. I reported this error ten or more years ago, and she returned “will not fix” due to compatibility issues. If you can wait for Java 7 to appear, I believe that nio2 has fixed it, of course I asked for it, but who knows when it will be?
And even if you have it all, all you know is that the data was sent. You do not know anything about this received or processed by the recipient application. If you need to, you must create it in your application protocol.
source share