As per my understanding, a Java thread dump is the dump of all threads depicting what every thread in the JVM is doing or state of each thread at a specific point of time. Similarly, a memory dump represents the health of memory at a specific point of time.
Does any tool provide a way to take a memory or thread dump of an hour or more so that if I want to analyze the state for an hour I can do that?
I don't see any way of doing it in jconsole, jvisualvm, or dynatrace. Maybe there is a way but I am not finding it?
As for the memory dump: Dumping memory regularly would need one really, really big and very, very fast filesystem. So no, I woudn't advise on doing that. Better to define some triggers based on gc activity or other conditions.
Regarding the Stack-Traces: If you face race conditions, phases where your (heavily multithreaded?) application freezes or slows down for all users, I've found it helpful to collect a few (3-5) thread dumps with 3 to 5 seconds offset in regular intervals (we started off with 5 min and as system grew more stable cut it down to 30m) and then compare these snapshots to each other identifying possible interference.
While the first iterations involved jstack, it later evolved to JMX based access to the java application and pulling database lock info at the same time.
So your question can be answered with a heartily: "It depends". Memory dumps should be pulled only if you see OutOfMemoryError
s. Thread dumps can be useful at times when there might be high traffic / freezes / thread congestions.