Java Code Examples for sun.tools.attach.HotSpotVirtualMachine#executeJCmd()
The following examples show how to use
sun.tools.attach.HotSpotVirtualMachine#executeJCmd() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JCmd.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 2
Source File: JCmd.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 3
Source File: JCmd.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 4
Source File: JCmd.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 5
Source File: JCmd.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 6
Source File: JmxModelImpl.java From visualvm with GNU General Public License v2.0 | 5 votes |
private boolean loadManagementAgentViaJcmd(VirtualMachine vm) throws IOException { if (vm instanceof HotSpotVirtualMachine) { HotSpotVirtualMachine hsvm = (HotSpotVirtualMachine) vm; InputStream in = null; try { byte b[] = new byte[256]; int n; in = hsvm.executeJCmd(ENABLE_LOCAL_AGENT_JCMD); do { n = in.read(b); if (n > 0) { String s = new String(b, 0, n, "UTF-8"); // NOI18N System.out.print(s); } } while (n > 0); return true; } catch (IOException ex) { LOGGER.log(Level.INFO, "jcmd command \""+ENABLE_LOCAL_AGENT_JCMD+"\" for PID "+vmid+" failed", ex); // NOI18N } finally { if (in != null) { in.close(); } } } return false; }
Example 7
Source File: JCmd.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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(); }
Example 8
Source File: JCmd.java From hottub with GNU General Public License v2.0 | 5 votes |
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(); }
Example 9
Source File: JCmd.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 10
Source File: JCmd.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 11
Source File: JCmd.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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(); }
Example 12
Source File: JCmd.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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(); }
Example 13
Source File: JCmd.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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(); }
Example 14
Source File: JCmd.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 15
Source File: JInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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); }
Example 16
Source File: JInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void commandLine(String pid) throws IOException { HotSpotVirtualMachine vm = (HotSpotVirtualMachine) attach(pid); InputStream in = vm.executeJCmd("VM.command_line"); drain(vm, in); }
Example 17
Source File: JInfo.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
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); }