本文整理汇总了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();
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}