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

后端 未结 3 2039
独厮守ぢ
独厮守ぢ 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条回答
  •  无人及你
    2021-01-28 05:32

    When the thread is blocked in an I/O call, it is still running as far as Java thread is concerned.

    Most profilers simply show thread state, which is defined as,

    • NEW A thread that has not yet started is in this state.
    • RUNNABLE A thread executing in the Java virtual machine is in this state.
    • BLOCKED A thread that is blocked waiting for a monitor lock is in this state.
    • WAITING A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
    • TIMED_WAITING A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
    • TERMINATED A thread that has exited is in this state.

    As you can see, thread's WAITING/BLOCKED state has nothing to do with I/O.

提交回复
热议问题