4

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?

Rahul khandelwal
  • 331
  • 3
  • 14

3 Answers3

6

Yes, thread dump and heap dump are stop-the-world operations in JDK 8.
HotSpot JVM performs them at the global safepoint.

See this and this answers for more information.

apangin
  • 92,924
  • 10
  • 193
  • 247
4

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

I think a there would be a periodic Stop-the-world pause when a thread snapshot is taken.

https://dzone.com/articles/logging-stop-world-pauses-jvm

It is not changing the state of a thread in a traditional sense.

vavasthi
  • 922
  • 5
  • 14