jmap转储无法正常工作

时间:2013-08-16 08:48:56

标签: java heap dump jmap

没有抛出异常,但我仍然无法在我的桌面文件夹中找到dump.bin文件,我的路径错了吗?

 public static void dumpHeap()
        {
            System.out.println("dumping data");

            String name = ManagementFactory.getRuntimeMXBean().getName();
            System.out.println("name :" + name);
            String pid = name.substring(0, name.indexOf("@"));
            System.out.println("pid :" + pid);

            String[] cmd = { "jmap", "-dump:file=/Users/MyName/Desktop/dump.bin", pid };
            Process p;
            try {
                p = Runtime.getRuntime().exec(cmd);
            } catch (IOException e) {
                e.printStackTrace();
            }

1 个答案:

答案 0 :(得分:0)

我必须使用-F

强制它
public static void dumpHeap()

    {
        System.out.println("dumping data");

        String name = ManagementFactory.getRuntimeMXBean().getName();
        System.out.println("name :" + name);
        String pid = name.substring(0, name.indexOf("@"));
        System.out.println("pid :" + pid);

        String[] cmd = { "jmap", "-dump:file=/Users/MyName/Desktop/dump.bin", "-F", pid };
        Process p;
        try {
            p = Runtime.getRuntime().exec(cmd);
        } catch (IOException e) {
            e.printStackTrace();
        }