Magesh Kumaar Magesh Kumaar - 1 year ago 89
Java Question

Thread Dump during Full GC

I am wondering whether is it possible to obtain a Thread Dump during a Full GC.

What am currently doing now,

  • Obtain the Timestamp / Datestamp during a Full GC

  • Compare it with the logs and narrow down the request or action
    that might have triggered it.

I am just wondering whether is it possible to obtain a Thread Dump during Full GC.

Answer Source

You can't obtain any detailed information during a GC. You can now obtain the size of the various heaps via jstat but if your full GC is a stop-the-world- collection it means that everything else has stopped.

Additionally if you could obtaint his information, it is unlikely to be what you need to know, it is just one random sample so unless there is only one place which is triggering a gc e.g. a call to System.gc(), or only one place allocating, it won't be so useful.

If you want to know where System.gc() is being triggered you can use instrumentation (or a modified System class) to do a stack trace where it is explicitly called. I have done this before and found it was the DGC.

If you want to know where the highest allocation rate is, I suggest using a memory profiler. That is what the tools is for. It can show you stack traces of where the most/largest objects are being created.