本文整理汇总了Java中sun.tools.attach.HotSpotVirtualMachine.setFlag方法的典型用法代码示例。如果您正苦于以下问题:Java HotSpotVirtualMachine.setFlag方法的具体用法?Java HotSpotVirtualMachine.setFlag怎么用?Java HotSpotVirtualMachine.setFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.tools.attach.HotSpotVirtualMachine
的用法示例。
在下文中一共展示了HotSpotVirtualMachine.setFlag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFlagAttach
import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
private boolean setFlagAttach(HotSpotVirtualMachine vm, String flagName, String flagValue) throws Exception {
boolean result;
try {
vm.setFlag(flagName, flagValue);
result = true;
} catch (AttachOperationFailedException e) {
result = false;
}
return result;
}
示例2: setOptionUsingAttach
import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
private static void setOptionUsingAttach(String option, String value) throws Exception {
HotSpotVirtualMachine vm = (HotSpotVirtualMachine) VirtualMachine.attach(ProcessTools.getProcessId()+"");
InputStream in = vm.setFlag(option, value);
System.out.println("Result from setting '" + option + "' to '" + value + "' using attach:");
drain(vm, in);
System.out.println("-- end -- ");
}
示例3: testSetFlag
import sun.tools.attach.HotSpotVirtualMachine; //导入方法依赖的package包/类
public static void testSetFlag(String flagName, String initialFlagValue, String flagValue) throws Exception {
ProcessBuilder pb = runTarget(flagName, initialFlagValue);
Process target = pb.start();
try {
waitForReady(target);
int pid = (int)target.getPid();
HotSpotVirtualMachine vm = (HotSpotVirtualMachine)VirtualMachine.attach(((Integer)pid).toString());
// First set the value.
BufferedReader remoteDataReader = new BufferedReader(new InputStreamReader(
vm.setFlag(flagName, flagValue)));
String line;
while((line = remoteDataReader.readLine()) != null) {
System.out.println("setFlag: " + line);
// Just empty the stream.
}
remoteDataReader.close();
// Then read and make sure we get back the set value.
remoteDataReader = new BufferedReader(new InputStreamReader(vm.printFlag(flagName)));
boolean foundExpectedLine = false;
line = null;
while((line = remoteDataReader.readLine()) != null) {
System.out.println("getFlag: " + line);
if (line.equals("-XX:" + flagName + "=" + flagValue)) {
foundExpectedLine = true;
}
}
Asserts.assertTrue(foundExpectedLine, "Didn't get the expected output: '-XX:" + flagName + "=" + flagValue + "'");
vm.detach();
} finally {
target.destroy();
target.waitFor();
}
}