Search code examples
javaperformancejvisualvm

jvisualvm thread cpu time usage


I'm using the jvisualvm to monitor the running java program. when I dig into the details of thread cpu usage, I get the following picture. The CPU usage consists of file portions: Running, Sleeping, Wait, Park and Monitor.

I didn't find any official definition about the columns, so I'd like to know what are these columns really mean in java code.

  • Running: time used in executing.
  • Sleeping: Thread.sleep(long) ?
  • Wait: ?
  • Park: LockSupport.park ?
  • Monitor: ?

Thread CPU time usage


Solution

  • I made a simple test and found these columns can map to the java code operations:

    • Sleeping: Thread.sleep(..)
    • Wait: Object.wait(..)
    • Park: when you're using new concurrent objects introduce in jdk5+, which may used LockSupport.park.
    • Monitor: when invoke synchronized method/objects

    So, wait/park/monitor all means the thread is blocked, but blocked by different reasons.


    If a thread is waiting on a socket, the time may be counted on Running.

    enter image description here

    In this picture, Thread-pool-Bill is Running for most of time, but the truth is it is waiting on a socket for a very long time:

    "Thread-pool-Bill" - Thread t@42
       java.lang.Thread.State: RUNNABLE
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        - locked <79f0aad8> (a java.net.SocksSocketImpl)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)