java 线程 阻塞 等待,应该将被Java NIO Selector.select()阻塞的线程视为正在等待或正在运行...

The documentation of selectorObj.select() method states

This method performs a blocking

selection operation. It returns only

after at least one channel is

selected, this selector's wakeup

method is invoked, or the current

thread is interrupted, whichever comes

first.

I understand the documentation

The thread that is blocked by select method, shouldn't be waiting? When I run profiler I see the thread is in run mode instead of wait state.

Although, I accept that, it is not mentioned that the thread should be in wait state, but my assumption is that till the signal dispatcher thread provides some input regarding any activity on channel registered with selector; the thread should be in wait state.

Please provide me some help as to why my assumption could be wrong.

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值