WAIT和BLOCKED线程状态之间的区别 [英] Difference between WAIT and BLOCKED thread states

查看:190
本文介绍了WAIT和BLOCKED线程状态之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

线程状态WAIT和线程状态BLOCKED有什么区别?

What is the difference between thread state WAIT and thread state BLOCKED?

Thread.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

没有解释给我的区别。

推荐答案

线程一旦调用<$ c就进入等待状态对象上的$ c> wait()。这称为等待状态。
一旦线程达到等待状态,它将需要等到其他线程 notify() notifyAll()

A thread goes to wait state once it calls wait() on an Object. This is called Waiting State. Once a thread reaches waiting state, it will need to wait till some other thread notify() or notifyAll() on the object.

一旦通知此线程,它将无法运行。可能是其他线程也被通知(使用 notifyAll())或者第一个线程尚未完成其工作,因此它仍然被阻塞,直到它有机会。这称为阻止状态。

Once this thread is notified, it will not be runnable. It might be that other threads are also notified(using notifyAll()) or the first thread has not finished his work, so it is still blocked till it gets its chance. This is called Blocked State.

一旦其他线程离开并且这个线程有机会,它就会移动到Runnable状态,之后它是合格的选择基于JVM线程机制的工作并移动到运行状态。

Once other threads have left and its this thread chance, it moves to Runnable state after that it is eligible pick up work based on JVM threading mechanism and moves to run state.

这篇关于WAIT和BLOCKED线程状态之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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