Java - Reading from a buffered reader (from a socket) is pausing the thread

前端 未结 5 1820
逝去的感伤
逝去的感伤 2021-01-04 14:05

I have a thread that reads characters from a Buffered reader (created from a socket as follows):

inputStream = new BufferedReader(new InputStreamReader(clien         


        
5条回答
  •  被撕碎了的回忆
    2021-01-04 15:03

    java.io.InputStream.read() is a blocking call, which means if no data is available the thread halts until data becomes available.

    For non-blocking I/O, use classes from the java.nio package.

提交回复
热议问题