Java Code Examples for java.lang.management.RuntimeMXBean#getInputArguments()
The following examples show how to use
java.lang.management.RuntimeMXBean#getInputArguments() .
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: MiscUtils.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean checkIfDebugged() { try { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); List<String> args = runtime.getInputArguments(); for (String arg : args) { if ("-Xdebug".equals(arg)) { // NOI18N return true; } else if ("-agentlib:jdwp".equals(arg)) { // NOI18N // The idea of checking -agentlib:jdwp // is taken from org.netbeans.modules.sampler.InternalSampler return true; } else if (arg.startsWith("-agentlib:jdwp=")) { // NOI18N return true; } } } catch (SecurityException ex) { } return false; }
Example 2
Source File: EnvironmentInformation.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
/** * Gets the system parameters and environment parameters that were passed to the JVM on startup. * * @return The options passed to the JVM on startup. */ public static String getJvmStartupOptions() { try { final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); final StringBuilder bld = new StringBuilder(); for (String s : bean.getInputArguments()) { bld.append(s).append(' '); } return bld.toString(); } catch (Throwable t) { return UNKNOWN; } }
Example 3
Source File: JvmPropertyProvider.java From appstatus with Apache License 2.0 | 5 votes |
public Map<String, String> getProperties() { Map<String, String> map = new TreeMap<String, String>(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<String> aList = runtimeMXBean.getInputArguments(); String parameters = ""; for (int i = 0; i < aList.size(); i++) { parameters = parameters + " " + aList.get(i); } map.put("params", parameters); map.put("name", runtimeMXBean.getVmName()); map.put("vendor", runtimeMXBean.getVmVendor()); map.put("version", runtimeMXBean.getVmVersion()); map.put("specification", runtimeMXBean.getSpecVersion()); map.put("uptime", DurationFormatUtils.formatDurationHMS(runtimeMXBean.getUptime())); Date date = new Date(runtimeMXBean.getStartTime()); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); map.put("start time", sdf.format(date)); MemoryMXBean memory = ManagementFactory.getMemoryMXBean(); MemoryUsage heap = memory.getHeapMemoryUsage(); map.put("memory. (heap)", readableFileSize(heap.getUsed()) + "/" + readableFileSize(heap.getCommitted()) + " min:" + readableFileSize(heap.getInit()) + " max:" + readableFileSize(heap.getMax())); MemoryUsage nonheap = memory.getNonHeapMemoryUsage(); map.put("memory (non heap)", readableFileSize(nonheap.getUsed()) + "/" + readableFileSize(nonheap.getCommitted()) + " min:" + readableFileSize(nonheap.getInit()) + " max:" + readableFileSize(nonheap.getMax())); return map; }
Example 4
Source File: MagicSystem.java From magarena with GNU General Public License v3.0 | 5 votes |
/** * Gets VM arguments. */ public static String getRuntimeParameters() { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); StringBuilder params = new StringBuilder(); for (String param : bean.getInputArguments()) { params.append(param).append("\n"); } return params.toString(); }
Example 5
Source File: Main.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Map<String, String> getHostSystemProperties() { final Map<String, String> hostSystemProperties = new HashMap<String, String>(); try { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); String propertyName, propertyValue; for (String arg : runtime.getInputArguments()) { if (arg != null && arg.length() > 2 && arg.startsWith("-D")) { arg = arg.substring(2); int equalIndex = arg.indexOf("="); if (equalIndex >= 0) { //Things like -Djava.security.policy==/Users/kabir/tmp/permit.policy will end up here, and the extra '=' needs to be part of the value, //see http://docs.oracle.com/javase/6/docs/technotes/guides/security/PolicyFiles.html propertyName = arg.substring(0, equalIndex); propertyValue = arg.substring(equalIndex + 1); } else { propertyName = arg; propertyValue = null; } if (!hostSystemProperties.containsKey(propertyName)) { hostSystemProperties.put(propertyName, propertyValue); } } } } catch (Exception e) { STDERR.println(HostControllerLogger.ROOT_LOGGER.cannotAccessJvmInputArgument(e)); } return hostSystemProperties; }
Example 6
Source File: ProcessTools.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Get the string containing input arguments passed to the VM * * @return arguments */ public static String getVmInputArguments() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); List<String> args = runtime.getInputArguments(); StringBuilder result = new StringBuilder(); for (String arg : args) result.append(arg).append(' '); return result.toString(); }
Example 7
Source File: EnvironmentInformation.java From flink with Apache License 2.0 | 5 votes |
/** * Gets the system parameters and environment parameters that were passed to the JVM on startup. * * @return The options passed to the JVM on startup. */ public static String[] getJvmStartupOptionsArray() { try { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); List<String> options = bean.getInputArguments(); return options.toArray(new String[options.size()]); } catch (Throwable t) { return new String[0]; } }
Example 8
Source File: ProcessTools.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Get the string containing input arguments passed to the VM * * @return arguments */ public static String getVmInputArguments() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); List<String> args = runtime.getInputArguments(); StringBuilder result = new StringBuilder(); for (String arg : args) result.append(arg).append(' '); return result.toString(); }
Example 9
Source File: MyTestUtils.java From semanticvectors with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Spawn a child to execute the main method in Class childMain * using the same args and environment as the current runtime. * This method prevents a child processes from hanging * when its output buffers saturate by creating threads to * empty the output buffers. * @return The process, already started. Consider using waitForAndDestroy() to clean up afterwards. * @param childMain The Class to spawn, must contain main function * @param inputArgs arguments for the main class. Use null to pass no arguments. * @param in The child process will read input from this stream. Use null to avoid reading input. Always close() your stream when you are done or you may deadlock. * @param out The child process will write output to this stream. Use null to avoid writing output. * @param err The child process will write errors to this stream. Use null to avoid writing output. */ public static Process spawnChildProcess( Class<?> childMain, String[] inputArgs, InputStream in, OutputStream out, OutputStream err) throws IOException { //get the same arguments as used to start this JRE RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean(); List<String> arglist = rmxb.getInputArguments(); String cp = rmxb.getClassPath(); //construct "java <arguments> <main-class-name>" ArrayList<String> arguments = new ArrayList<String>(arglist); arguments.add(0, "java"); arguments.add("-classpath"); arguments.add(cp); arguments.add(childMain.getCanonicalName()); for (String arg : inputArgs) arguments.add(arg); //using ProcessBuilder initializes the child process with parent's env. ProcessBuilder pb = new ProcessBuilder(arguments); //redirecting STDERR to STDOUT needs to be done before starting if (err == out) { pb.redirectErrorStream(true); } Process proc; proc = pb.start(); //Might throw an IOException to calling method //setup stdin if (in != null) { new OutputReader(in, proc.getOutputStream()).start(); } //setup stdout if (out == null) { out = new NullOutputStream(); } new OutputReader(proc.getInputStream(), out).start(); //setup stderr if (!pb.redirectErrorStream()) { if (err == null) { err = new NullOutputStream(); } new OutputReader(proc.getErrorStream(), err).start(); } return proc; }
Example 10
Source File: FatJarMain.java From buck with Apache License 2.0 | 5 votes |
private static List<String> getJVMArguments() { RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); try { return runtimeMxBean.getInputArguments(); } catch (java.lang.SecurityException e) { // Do not have the ManagementPermission("monitor") permission return new ArrayList<String>(); } }
Example 11
Source File: ProcessTools.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Get the string containing input arguments passed to the VM * * @return arguments */ public static String getVmInputArguments() { RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean(); List<String> args = runtime.getInputArguments(); StringBuilder result = new StringBuilder(); for (String arg : args) result.append(arg).append(' '); return result.toString(); }
Example 12
Source File: JMServer.java From jmonitor with GNU General Public License v2.0 | 5 votes |
@HttpMapping(url = "/loadRuntimeInfo") public JSONObject doLoadRuntimeInfo(Map<String, Object> param) { try { String app = ((HttpServletRequest) param.get(JMDispatcher.REQ)).getParameter("app"); RuntimeMXBean mBean = JMConnManager.getRuntimeMBean(app); ClassLoadingMXBean cBean = JMConnManager.getClassMbean(app); Map<String, String> props = mBean.getSystemProperties(); DateFormat format = DateFormat.getInstance(); List<String> input = mBean.getInputArguments(); Date date = new Date(mBean.getStartTime()); TreeMap<String, Object> data = new TreeMap<String, Object>(); data.put("apppid", mBean.getName()); data.put("startparam", input.toString()); data.put("starttime", format.format(date)); data.put("classLoadedNow", cBean.getLoadedClassCount()); data.put("classUnloadedAll", cBean.getUnloadedClassCount()); data.put("classLoadedAll", cBean.getTotalLoadedClassCount()); data.putAll(props); JSONObject json = new JSONObject(true); json.putAll(data); return json; } catch (IOException e) { throw new RuntimeException(e); } }
Example 13
Source File: TLCRuntime.java From tlaplus with MIT License | 5 votes |
/** * @return The non-heap memory JVM memory set with -XX:MaxDirectMemorySize in Bytes */ public long getNonHeapPhysicalMemory() { // 64MB by default. This happens to be the JVM default for // XX:MaxDirectMemorySize if no other value is given. long l = (64L * 1024L * 1024L); final RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); final List<String> arguments = RuntimemxBean.getInputArguments(); for (String arg : arguments) { if (arg.toLowerCase().startsWith("-xx:maxdirectmemorysize")) { String[] strings = arg.split("="); String mem = strings[1].toLowerCase(); if (mem.endsWith("g")) { l = Long.parseLong(mem.substring(0, mem.length() -1)); l = l << 30; break; } else if (mem.endsWith("m")) { l = Long.parseLong(mem.substring(0, mem.length() -1)); l = l << 20; break; } else if (mem.endsWith("k")) { l = Long.parseLong(mem.substring(0, mem.length() -1)); l = l << 10; break; } else { l = Long.parseLong(mem.substring(0, mem.length())); break; } } } return l; }
Example 14
Source File: ApplicationServerService.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private String getVMArguments() { final StringBuilder result = new StringBuilder(1024); final RuntimeMXBean rmBean = ManagementFactory.getRuntimeMXBean(); final List<String> inputArguments = rmBean.getInputArguments(); for (String arg : inputArguments) { result.append(arg).append(" "); } return result.toString(); }
Example 15
Source File: GetMemberConfigInformationFunction.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private List<String> getJvmInputArguments() { RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); return runtimeBean.getInputArguments(); }
Example 16
Source File: CheckBoxTableComboDefaultButton.java From pentaho-kettle with Apache License 2.0 | 4 votes |
protected boolean checkCommandLineArgs() { this.errorDialogProceed = true; if ( null != connectionForm && JmsProvider.ConnectionType.ACTIVEMQ.equals( JmsProvider.ConnectionType.valueOf( connectionForm.getConnectionType() ) ) ) { RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); boolean showDialog = false; for ( String arg : runtimeMXBean.getInputArguments() ) { showDialog = arg.contains( JAVAX_SSL_KEYSTORE_PASS ) || arg.contains( JAVAX_SSL_KEYSTORE_PATH ) || arg.contains( JAVAX_SSL_TRUSTSTORE_PASS ) || arg.contains( JAVAX_SSL_TRUSTSTORE_PATH ) || arg.contains( HTTPS_CIPHER_SUITES ); if ( showDialog ) { break; } } if ( showDialog ) { this.errorDialogProceed = false; final BaseDialog errorDlg = new BaseMessageDialog( parentComposite.getShell(), getString( PKG, "JmsDialog.Security.ACTIVEMQ_COMMAND_LINE_ARGS_MISMATCH_TITLE" ), getString( PKG, "JmsDialog.Security.ACTIVEMQ_COMMAND_LINE_ARGS_MISMATCH_MSG" ), 350 ); final Map<String, Listener> buttons = new HashMap(); buttons .put( getString( PKG, "JmsDialog.Security.ACTIVEMQ_COMMAND_LINE_ARGS_MISMATCH_YES" ), event -> { errorDlg.dispose(); this.errorDialogProceed = true; } ); buttons .put( getString( PKG, "JmsDialog.Security.ACTIVEMQ_COMMAND_LINE_ARGS_MISMATCH_NO" ), event -> { errorDlg.dispose(); this.errorDialogProceed = false; } ); errorDlg.setButtons( buttons ); errorDlg.open(); } } return this.errorDialogProceed; }
Example 17
Source File: JavaAgentPathResolver.java From pinpoint with Apache License 2.0 | 4 votes |
@VisibleForTesting List<String> getInputArguments() { RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); return runtimeMXBean.getInputArguments(); }
Example 18
Source File: GetMemberConfigInformationFunction.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
private List<String> getJvmInputArguments() { RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); return runtimeBean.getInputArguments(); }
Example 19
Source File: ConfigCommandsDUnitTest.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public void testDescribeConfig() throws ClassNotFoundException, IOException { createDefaultSetup(null); final VM vm1 = Host.getHost(0).getVM(1); final String vm1Name = "Member1"; final String controllerName = "Member2"; /*** * Create properties for the controller VM */ final Properties localProps = new Properties(); localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info"); localProps.setProperty(DistributionConfig.STATISTIC_SAMPLING_ENABLED_NAME, "true"); localProps.setProperty(DistributionConfig.ENABLE_TIME_STATISTICS_NAME, "true"); localProps.setProperty(DistributionConfig.NAME_NAME, controllerName); localProps.setProperty(DistributionConfig.GROUPS_NAME, "G1"); getSystem(localProps); Cache cache = getCache(); int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(1); CacheServer cs = getCache().addCacheServer(); cs.setPort(ports[0]); cs.setMaxThreads(10); cs.setMaxConnections(9); cs.start(); RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); List<String> jvmArgs = runtimeBean.getInputArguments(); getLogWriter().info("#SB Actual JVM Args : "); for (String jvmArg : jvmArgs) { getLogWriter().info("#SB JVM " + jvmArg); } InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem(); DistributionConfig config = system.getConfig(); config.setArchiveFileSizeLimit(1000); String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName; CommandProcessor cmdProcessor = new CommandProcessor(); cmdProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process(); CommandResult cmdResult = executeCommand(command); String resultStr = commandResultToString(cmdResult); getLogWriter().info("#SB Hiding the defaults\n" + resultStr); assertEquals(true, cmdResult.getStatus().equals(Status.OK)); assertEquals(true, resultStr.contains("G1")); assertEquals(true, resultStr.contains(controllerName)); assertEquals(true, resultStr.contains("archive-file-size-limit")); assertEquals(true, !resultStr.contains("copy-on-read")); cmdResult = executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS + "=false"); resultStr = commandResultToString(cmdResult); getLogWriter().info("#SB No hiding of defaults\n" + resultStr); assertEquals(true, cmdResult.getStatus().equals(Status.OK)); assertEquals(true, resultStr.contains("is-server")); assertEquals(true, resultStr.contains(controllerName)); assertEquals(true, resultStr.contains("copy-on-read")); cs.stop(); }
Example 20
Source File: AllureUtils.java From marathonv5 with Apache License 2.0 | 4 votes |
private static List<String> getVMArgs() { RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean(); return new ArrayList<String>(runtimeMxBean.getInputArguments()); }