“阻止计数”是什么和“等待计数”在Java线程中意味着什么? [英] What does "blocked Count" and "Waited Count" in a Java Thread mean?

查看:466
本文介绍了“阻止计数”是什么和“等待计数”在Java线程中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JConsole观看一个帖子,它显示

I use JConsole to watch a thread, it shows

name: Thread-6
state:BLOCKED  sun.misc.Launcher$AppClassLoader@19821f ,owner: Thread-3
blocked Count:199,645  Waited Count: 2,610

199,645和2,610:这是件坏事吗?

199,645 and 2,610: Is that a bad thing?

推荐答案

如果您的应用程序未满足您的要求,基于这些数字,因为存在很多锁争用。等待是它等待通知(Object.wait())但是阻塞意味着它试图获取一个锁而不能,因为另一个线程持有它。

If your application is not running meeting your requirements, based on these numbers that would be because there is a lot of lock contention. Waiting is that it waits for a notification (Object.wait()) but blocked means that it tries to acquire a lock and cannot because another thread holds it.

From < a href =http://geekexplains.blogspot.ca/2008/07/threadstate-in-java-blocked-vs-waiting.html =nofollow noreferrer> http://geekexplains.blogspot.ca/2008 /07/threadstate-in-java-blocked-vs-waiting.html

BLOCKED状态和WAITING / TIMED_WAITING状态之间的区别?

Difference between BLOCKED state and WAITING / TIMED_WAITING states?

当一个线程调用Object.wait方法时,它会释放所有获取的监视器,并进入WAITING(如果我们调用wait方法的超时版本,则为TIMED_WAITING)状态。现在,当通过notify()或notifyAll()调用同一对象通知线程时,线程的等待状态结束,线程开始尝试重新获得它在等待调用时获取的所有监视器。有一次,可能有几个线程试图重新获得(或者第一次获得)他们的监视器。如果多个线程尝试获取特定对象的监视器,则只有一个线程(由JVM调度程序选择)被授予监视器,而所有其他线程都被置于BLOCKED状态。

When a thread calls Object.wait method, it releases all the acquired monitors and is put into WAITING (or TIMED_WAITING if we call the timeout versions of the wait method) state. Now when the thread is notified either by notify() or by notifyAll() call on the same object then the waiting state of the thread ends and the thread starts attempting to regain all the monitors which it had acquired at the time of wait call. At one time there may be several threads trying to regain (or maybe gain for the first time) their monitors. If more than one threads attempt to acquire the monitor of a particular object then only one thread (selected by the JVM scheduler) is granted the monitor and all other threads are put into BLOCKED state.

这篇关于“阻止计数”是什么和“等待计数”在Java线程中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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