What does “blocked Count” and “Waited Count” in a Java Thread mean?

前端 未结 2 347
一向
一向 2021-01-13 23:19

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  Wai         


        
2条回答
  •  礼貌的吻别
    2021-01-13 23:44

    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 http://geekexplains.blogspot.ca/2008/07/threadstate-in-java-blocked-vs-waiting.html

    Difference between BLOCKED state and WAITING / TIMED_WAITING states?

    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.

提交回复
热议问题