For me below are the most probable definitions for asynchronous and non-blocking I/O:
Asynchronous I/O:
In asynchronous I/O applications return immediately and OS will let them know when the bytes are available for processing.
NON-blocking I/O:
Here application returns immediately what ever data available and application should have polling mechanism to find out when more data is ready.
After knowing these definitions if we analyze java channels i.e. SocketChannel
, ServerSocketChannel
, DatagramSocketChannel
then we can find that these channels can be used as blocking or non-blocking mode by the method configureBlocking(boolean block)
. and assume that we are using them as non-blocking mode. So here comes the questions:
if i will use Selector
i.e. register channels to a selector
whether it is Asynchronous I/O or NON-blocking I/O?
I feel this is Asynchronous I/O in java if and only if underlying operating system is informing the java application about readiness selection of a channel. Else it is non-blocking I/O and selector
is just a mechanism which helps us polling the above mention channels as i mention in the definition. Which is correct? Thanks in advance.
EDIT:
I have answered one part of the question i.e. types of I/O and how java facilitates these functionality.
But one question still remains whether all these functionalities are provides by java is simulated at java layer or it uses underlaying OS to facilitate? Assume the underlaying OS has all the support for these functionalities.
Please refer to the answer.