Search code examples
javaheap-memoryjmap

Execute jmap inside java program to generate dumps for the same process


Is it possible to execute 'jmap' at different spots inside my java-programm to generate dump files. I guess one must get the own process ID and than execute the command via Runtime().exec() or similar. Didn't succeed though.

Chris


Solution

  • Try:

    String name = ManagementFactory.getRuntimeMXBean().getName();
    String[] str = name.split("@");
    Runtime.getRuntime().exec("jmap -dump:file=YOURFILENAME " + str[0]);