VisualVM - Thread State

Can someone explain to me the difference between the Sleeping , Wait , Park and Monitor states in VisualVM.

enter image description here

Here is what I found:

Running : the thread is still running.

Sleeping : thread is sleep (yield () method is called on the thread object)
Wait : a thread is blocked by a mutex or barrier and waits for another thread to exit the lock
Park : Parked threads are paused until they receive permission. Disabling a stream is usually done by calling the unpark () method on the stream object.
Monitor : threads wait for a condition to return to resume execution

What I can’t understand is a state park that actually stops the flow? How to determine in the code what caused the thread to pause its execution?

Can anyone help me in this regard.

Thank.

+46
java jvm visualvm jvisualvm
Dec 10 '14 at 16:35
source share
2 answers

I used google, and on the first page that appeared there was a very good chart that pretty much describes everything you need / need to know. Next time it's worth a google try for these types of questions.

enter image description here

1) New

A thread is in a new state if you create an instance of the Thread class, but before calling the start () method.

2) Runnable

The thread is in runnable state after calling the start () method, but the thread scheduler did not select it for the current thread.

3) Execution

The thread is in a running state if the thread scheduler has selected it.

4) Waiting time

Timeout is the state of the thread for a waiting thread with a given timeout. The thread is idle due to a call from one of the following methods with a specified positive timeout:

  • Thread.sleep (going to bed)
  • Object.wait (timeout)
  • Thread.join (timeout)
  • LockSupport.parkNanos (timeout)
  • LockSupport.parkUntil (timeout)

5) Non-Runnable (Blocked)

This is a state where the thread is still alive, but currently it cannot be started.

6) Ends

A thread ends or is dead when its run () method exits.

Hope this answers your question :).

Parking:

Disables the current thread for thread scheduling purposes, if permission is available.

Streams are parked or paused if you want to call it that because it does not have permission to execute. After permission is granted, the thread will be inaccurate and executed.

LockSupport permissions are associated with streams (i.e., the resolution is transferred to a specific stream) and do not accumulate (i.e. there can only be one permission per stream, when the stream consumes permission, it disappears).

+27
Dec 10 '14 at 16:50
source share

VisualVM maps the state of the Java thread (as described in @Maciej's answer) to the state represented in its interface as follows:

 BLOCKED -> Monitor RUNNABLE -> Running WAITING/TIMED_WAITING -> Sleeping/Park/Wait (see below) TERMINATED/NEW -> Zombie 

Sleeping and Park are specific timed cases:

 Sleeping: specifically waiting in Thread.sleep(). Park: specifically waiting in sun.misc.Unsafe.park() (presumably via LockSupport). 

(The mapping is done in ThreadMXBeanDataManager.java .)

A brief (and non-authoritative) discussion of the state of the Java thread can be found here .

EDIT ADD:

It is also worth noting that blocking threads when calling their own methods is displayed in the JVM as RUNNABLE , and therefore they are passed to VisualVM as Running (and consume 100% CPU).

+18
Apr 6 '16 at 11:01
source share



All Articles