我是靠谱客的博主 糟糕大雁,最近开发中收集的这篇文章主要介绍blocked java线程_Java线程中wait状态和block状态的区别?,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Thread is in the Blocked state while waiting for the monitor lock to enter a synchronized block or method or to reenter a synchronized block or method after calling Object.wait().

这个地方是说synchronized会导致线程进入Blocked状态,Object.wait()导致线程进入Waiting状态,Waiting线程被其他线程调用Object.notify()唤醒之后,重新获取对象上的锁的时候也会进入Blocked状态

* The current thread must own this object's monitor. The thread

* releases ownership of this monitor and waits until another thread

* notifies threads waiting on this object's monitor to wake up

* either through a call to the {@codenotify} method or the

* {@codenotifyAll} method. The thread then waits until it can

* re-obtain ownership of the monitor and resumes execution.

这是Object.wait()方法的注释,最后一句指明被唤醒的线程需要重新获取到对象的锁才能恢复执行

* The awakened thread will not be able to proceed until the current

* thread relinquishes the lock on this object. The awakened thread will

* compete in the usual manner with any other threads that might be

* actively competing to synchronize on this object; for example, the

* awakened thread enjoys no reliable privilege or disadvantage in being

* the next thread to lock this object.

这是Object.notify()方法的注释,第一句也说被唤醒的线程需要获取对象的锁

也就是说只有synchronized会导致线程进入Blocked状态,Waiting状态只能进入Blocked状态,获取锁之后才能恢复执行。

最后

以上就是糟糕大雁为你收集整理的blocked java线程_Java线程中wait状态和block状态的区别?的全部内容,希望文章能够帮你解决blocked java线程_Java线程中wait状态和block状态的区别?所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部