javajava-8jvmjvm-hotspotjstack

Does running JStack on java 8 stops all threads?


I am executing JStack command for taking thread dumps on certain interval.

I have observed that whenever JStack is executing, all threads on target process stop. I came to this conclusion after looking at my log4j 2 logs where I found no logging for the durations of JStack runs.

Can someone tell me does JSTack suspends/stops all threads in target process?


Solution

  • Taking the stack trace of any thread (even just one) brings all the threads to safepoint. You can see this with

    This prints every time the JVM is stopped for any reason (not just GC)

    -XX:+PrintGCApplicationStoppedTime
    

    This prints the statistics including the reason for the stop.

    -XX:+PrintSafepointStatistics -XX:PrintSafepointStatisticsCount=1
    

    There is a plan to introduce a thread specific stop however jstack needs to safepoint every thread.