Blocking in terms of java.io/java.nio

后端 未结 3 1893
北海茫月
北海茫月 2021-01-29 09:02

I just read ...

Classes that work with streams are located in two packages: java.io and java.nio. Classes from the former implement blocking of input/

3条回答
  •  故里飘歌
    2021-01-29 09:10

    Consider a situation where you have 2 threads. Both threads are reading from single socket streams. Here we are concerned about the source bytes which we are reading as well as we need to check in terms of Multi-threading. The reason is due to Blocking I/O

    • Blocking I/O: This is I/O which waits indefinitely for availability of source. The execution of thread waits at that point and it increases chances of Hang or Slowness of your application. java.io package is example of this type

    • Non-Blocking I/O: This is I/O which will not wait for source for infinite time, but will return immediately. java.nio package is example of this type

提交回复
热议问题