Java线程 - 阻止状态 [英] Java Thread - blocked status

查看:159
本文介绍了Java线程 - 阻止状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的问题。如果线程在IO操作中忙,为什么不将其视为RUNNING状态?如果IO操作需要很长时间,则表示该线程正在执行其工作。如果一个线程在实际工作时怎么称为BLOCKED?

I have a very basic question. If a thread is busy in IO operation why it is not considered in a RUNNING state? If the IO operation is taking long time it means that the thread is doing its work. How can a thread be called BLOCKED when it is actually doing it's work?

推荐答案

我不知道你在哪里读到的执行IO时,线程处于BLOCKED状态。 BLOCKED州文档说:

I don't know where you read that a thread is in the BLOCKED state when doing IO. The BLOCKED state documentation says:


线程状态被阻塞等待监视器锁定。处于阻塞状态的线程正在等待监视器锁定以在调用Object.wait之后输入同步块/方法或重新输入同步块/方法。

Thread state for a thread blocked waiting for a monitor lock. A thread in the blocked state is waiting for a monitor lock to enter a synchronized block/method or reenter a synchronized block/method after calling Object.wait.

所以,不,一个线程在执行IO时不处于阻塞状态(除非当然读取或写入强制它等待对象的监视器。)

So, no, a thread is not in a blocked state while doing IO (unless of course reading or writing forces it to wait on an object's monitor).

这篇关于Java线程 - 阻止状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆