Class DumpsManager

java.lang.Object
org.apache.juneau.rest.server.management.DumpsManager

public class DumpsManager extends Object
Shared worker for the diagnostic dump endpoints (/threaddump, /heapdump).

Both the *Mixin and *Resource flavors delegate here so the two forms cannot drift — the same shared-worker pattern the health and metrics surfaces use.

Thread dump is rendered from the JDK-standard ThreadMXBean (always available). Heap dump is produced via the HotSpot HotSpotDiagnosticMXBean#dumpHeap(String,boolean) method, invoked reflectively so this module carries no compile-time dependency on com.sun.management — on a non-HotSpot JVM the heap dump degrades cleanly (the endpoints surface that as HTTP 501).

Exposure is governed by DumpsSettings resolved from the bean store; both dumps are deny-by-default — see DumpsSettings.

See Also:
Since:
10.0.0
  • Constructor Details

  • Method Details

    • resolveSettings

      Resolves the DumpsSettings from the host context's bean store, falling back to the deny-all default.
      Parameters:
      context - The REST context whose bean store is searched. May be null.
      Returns:
      The registered settings, or DumpsSettings.DEFAULT when none is registered.
    • threadDump

      public String threadDump()
      Renders a full thread dump from the ThreadMXBean.
      Returns:
      A human-readable thread dump (never null or empty).
    • heapDump

      public boolean heapDump(File target, boolean live)
      Writes a heap dump (hprof) to the supplied file via the HotSpot HotSpotDiagnosticMXBean.

      Invoked reflectively to avoid a compile-time dependency on com.sun.management. The target file must not already exist (a dumpHeap requirement).

      Parameters:
      target - The hprof output file. Must not be null (and must not pre-exist).
      live - If true, dump only live (reachable) objects.
      Returns:
      true if the dump was written; false if this JVM has no HotSpot heap-dump support (the endpoints surface that as HTTP 501).
    • heapDumpStream

      public InputStream heapDumpStream(boolean live) throws IOException
      Produces a heap dump and returns it as a self-deleting input stream.

      Writes the hprof to a fresh temp file (the dumpHeap no-pre-existing-file requirement is satisfied by deleting the just-created temp file before the dump), then returns a stream over it that deletes the backing file when closed.

      Parameters:
      live - If true, dump only live (reachable) objects.
      Returns:
      A stream over the hprof file, or null if this JVM has no HotSpot heap-dump support.
      Throws:
      IOException - If the temp file could not be created or opened.