当前位置: 首页>>代码示例>>Java>>正文


Java HotSpotVirtualMachine.executeJCmd方法代码示例

本文整理汇总了Java中sun.tools.attach.HotSpotVirtualMachine.executeJCmd方法的典型用法代码示例。如果您正苦于以下问题:Java HotSpotVirtualMachine.executeJCmd方法的具体用法?Java HotSpotVirtualMachine.executeJCmd怎么用?Java HotSpotVirtualMachine.executeJCmd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.tools.attach.HotSpotVirtualMachine的用法示例。


在下文中一共展示了HotSpotVirtualMachine.executeJCmd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeCommandForPid

import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
private static void executeCommandForPid(String pid, String command)
    throws AttachNotSupportedException, IOException,
           UnsupportedEncodingException {
    VirtualMachine vm = VirtualMachine.attach(pid);

    // Cast to HotSpotVirtualMachine as this is an
    // implementation specific method.
    HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
    String lines[] = command.split("\\n");
    for (String line : lines) {
        if (line.trim().equals("stop")) {
            break;
        }
        try (InputStream in = hvm.executeJCmd(line);) {
            // read to EOF and just print output
            byte b[] = new byte[256];
            int n;
            boolean messagePrinted = false;
            do {
                n = in.read(b);
                if (n > 0) {
                    String s = new String(b, 0, n, "UTF-8");
                    System.out.print(s);
                    messagePrinted = true;
                }
            } while (n > 0);
            if (!messagePrinted) {
                System.out.println("Command executed successfully");
            }
        }
    }
    vm.detach();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:JCmd.java

示例2: parseFlags

import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
public static List<JVMFlagItem> parseFlags(String pid) {
    try {
        VirtualMachine vm = VirtualMachine.attach(pid);
        HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
        InputStream in = hvm.executeJCmd("VM.flags -all");
        byte buffer[] = new byte[256];
        StringBuilder sbd = new StringBuilder(100000);
        int n;
        do {
            n = in.read(buffer);
            if (n > 0) {
                String s = new String(buffer, 0, n, "UTF-8");
                sbd.append(s);
            }
        } while (n > 0);
        in.close();
        vm.detach();
        String[] flags = sbd.toString().split("\n");
        List<JVMFlagItem> result = Lists.newArrayListWithCapacity(128);
        Pattern ptn = Pattern.compile("\\s*([^\\s]+)\\s+([^\\s]+)\\s+(=|:=)([^\\{]+)\\{(.*)\\}");
        for (int i = 1; i < flags.length; i++) {
            Matcher m = ptn.matcher(flags[i]);
            if (m.find()) {
                result.add(JVMFlagItem.builder().flagName(m.group(2)).original(m.group(3).equals("=")).value(m.group(4).trim()).type(m.group(5)).build());
            }
        }
        return result;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:peiliping,项目名称:excalibur,代码行数:33,代码来源:Util.java

示例3: executeCommandForPid

import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
private static void executeCommandForPid(String pid, String command)
    throws AttachNotSupportedException, IOException,
           UnsupportedEncodingException {
    VirtualMachine vm = VirtualMachine.attach(pid);

    // Cast to HotSpotVirtualMachine as this is an
    // implementation specific method.
    HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm;
    String lines[] = command.split("\\n");
    for (String line : lines) {
        if (line.trim().equals("stop")) {
            break;
        }
        try (InputStream in = hvm.executeJCmd(line);) {
            // read to EOF and just print output
            byte b[] = new byte[256];
            int n;
            do {
                n = in.read(b);
                if (n > 0) {
                    String s = new String(b, 0, n, "UTF-8");
                    System.out.print(s);
                }
            } while (n > 0);
        }
    }
    vm.detach();
}
 
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:29,代码来源:JCmd.java

示例4: flags

import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
private static void flags(String pid) throws IOException {
    HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
    InputStream in = vm.executeJCmd("VM.flags");
    System.out.println("VM Flags:");
    drain(vm, in);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:JInfo.java

示例5: commandLine

import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
private static void commandLine(String pid) throws IOException {
    HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
    InputStream in = vm.executeJCmd("VM.command_line");
    drain(vm, in);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:JInfo.java

示例6: sysprops

import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
private static void sysprops(String pid) throws IOException {
    HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid);
    InputStream in = vm.executeJCmd("VM.system_properties");
    System.out.println("Java System Properties:");
    drain(vm, in);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:JInfo.java


注:本文中的sun.tools.attach.HotSpotVirtualMachine.executeJCmd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。