Should thread blocked by java NIO Selector.select() be considered waiting or running

后端 未结 3 2041
独厮守ぢ
独厮守ぢ 2021-01-28 05:01

The documentation of selectorObj.select() method states

This method performs a blocking selection operation. It returns only after at l

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 05:31

    Normally the select operation invokes the poll(...) system function.

    select() provides the kernel with a list of file descriptors that it needs to monitor for read/write/error conditions as well as a timeout value. The kernel registers the process/thread with the associated channel's select function and puts the process/thread to sleep. Once the associated channel is ready or a timer has been expired, the kernel wakes up the registered process/thread. Note that this thread is the kernel thread and not the java application thread.

    I do not see a reason for the thread doing select to be in WAIT state (Unless the implementation of the Selector returned by the Selector provider explicitly did a wait in the select() function).

提交回复
热议问题