Java Code Examples for java.lang.management.ManagementFactory#getRuntimeMXBean()

The following examples show how to use java.lang.management.ManagementFactory#getRuntimeMXBean() . 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: VMLogger.java    From openjdk-systemtest with Apache License 2.0 6 votes vote down vote up
private void initialiseProxies() {
    runtimeBean  = ManagementFactory.getRuntimeMXBean();
    osBean       = ManagementFactory.getOperatingSystemMXBean();
    classBean    = ManagementFactory.getClassLoadingMXBean();
    
    if (!(compiler.equals("")))
    {	
        compBean  = ManagementFactory.getCompilationMXBean();
    }
    
    threadBean   = ManagementFactory.getThreadMXBean();
    memBean      = ManagementFactory.getMemoryMXBean();
    logBean      = LogManager.getLoggingMXBean();

    memPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
    memMgrBeans  = ManagementFactory.getMemoryManagerMXBeans();
    gcBeans      = ManagementFactory.getGarbageCollectorMXBeans();
}
 
Example 2
Source File: JdpController.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static Integer getProcessId() {
    try {
        // Get the current process id using a reflection hack
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        Field jvm = runtime.getClass().getDeclaredField("jvm");
        jvm.setAccessible(true);

        VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
        Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
        pid_method.setAccessible(true);
        Integer pid = (Integer) pid_method.invoke(mgmt);
        return pid;
    } catch(Exception ex) {
        return null;
    }
}
 
Example 3
Source File: TransitionsTestExecutor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void executeTestFor(int compilationPolicy, String testName) throws Throwable {
    String policy = "-XX:CompilationPolicyChoice=" + compilationPolicy;

    // Get runtime arguments including VM options given to this executor
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    List<String> vmArgs = runtime.getInputArguments();

    // Construct execution command with compilation policy choice and test name
    List<String> args = new ArrayList<>(vmArgs);
    Collections.addAll(args, policy, testName);

    OutputAnalyzer out = ProcessTools.executeTestJvm(args.toArray(new String[args.size()]));
    int exitCode = out.getExitValue();
    if (exitCode != 0) {
        throw new Error("Test execution failed with exit code " + exitCode);
    }
}
 
Example 4
Source File: Test7194254.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 5
Source File: HostControllerService.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 6
Source File: Management.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * @return Process CPU time in nanoseconds
 */
public static long getPID() {
  String pid = null;
  if ( mx == null ) {
    mx = ManagementFactory.getRuntimeMXBean();
  }

  pid = mx.getName();
  int indexOf = pid.indexOf( "@" );
  if ( indexOf > 0 ) {
    pid = pid.substring( 0, indexOf );
  }
  return Const.toInt( pid, -1 );
}
 
Example 7
Source File: JavaagentContainer.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private static List<String> getJacocoArgsFromCurrentJvm() {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    List<String> arguments = runtimeMXBean.getInputArguments();
    List<String> jacocoArgs = Lists.newArrayList();
    for (String argument : arguments) {
        if (argument.startsWith("-javaagent:") && argument.contains("jacoco")) {
            jacocoArgs.add(argument + ",inclbootstrapclasses=true,includes=org.glowroot.*");
            break;
        }
    }
    return jacocoArgs;
}
 
Example 8
Source File: ProcessTools.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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: UptimeSampler.java    From kieker with Apache License 2.0 5 votes vote down vote up
@Override
protected IMonitoringRecord[] createNewMonitoringRecords(final long timestamp, final String hostname, final String vmName,
		final IMonitoringController monitoringCtr) {
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createJVMUpTimeSignature())) {
		return new IMonitoringRecord[] {};
	}

	final RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();

	return new IMonitoringRecord[] { new UptimeRecord(timestamp, hostname, vmName, runtimeBean.getUptime()), };
}
 
Example 10
Source File: TestThreadDumpMonitorContention.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static String getPid() {
    RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
    String vmname = runtimebean.getName();
    int i = vmname.indexOf('@');
    if (i != -1) {
        vmname = vmname.substring(0, i);
    }
    return vmname;
}
 
Example 11
Source File: EnvironmentInformation.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the version of the JVM in the form "VM_Name - Vendor  - Spec/Version".
 *
 * @return The JVM version.
 */
public static String getJvmVersion() {
	try {
		final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
		return bean.getVmName() + " - " + bean.getVmVendor() + " - " + bean.getSpecVersion() + '/' + bean.getVmVersion();
	}
	catch (Throwable t) {
		return UNKNOWN;
	}
}
 
Example 12
Source File: LowLevelCarreraConsumer.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
private String genConsumerId() {
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    String name = runtime.getName(); // format: "pid@hostname"
    return name + "#" + consumerNumber.getAndIncrement();
}
 
Example 13
Source File: ProcessTools.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the process id of the current running Java process
 *
 * @return Process id
 */
public static int getProcessId() throws Exception {

  // Get the current process id using a reflection hack
  RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
  Field jvm = runtime.getClass().getDeclaredField("jvm");

  jvm.setAccessible(true);
  VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);

  Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");

  pid_method.setAccessible(true);

  int pid = (Integer) pid_method.invoke(mgmt);

  return pid;
}
 
Example 14
Source File: ProcessTools.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the process id of the current running Java process
 *
 * @return Process id
 */
public static int getProcessId() throws Exception {

    // Get the current process id using a reflection hack
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    Field jvm = runtime.getClass().getDeclaredField("jvm");

    jvm.setAccessible(true);
    VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);

    Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");

    pid_method.setAccessible(true);

    int pid = (Integer) pid_method.invoke(mgmt);

    return pid;
}
 
Example 15
Source File: ProcessTools.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the process id of the current running Java process
 *
 * @return Process id
 */
public static int getProcessId() throws Exception {

  // Get the current process id using a reflection hack
  RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
  Field jvm = runtime.getClass().getDeclaredField("jvm");

  jvm.setAccessible(true);
  VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);

  Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");

  pid_method.setAccessible(true);

  int pid = (Integer) pid_method.invoke(mgmt);

  return pid;
}
 
Example 16
Source File: ProcessTools.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the process id of the current running Java process
 *
 * @return Process id
 */
public static int getProcessId() throws Exception {

    // Get the current process id using a reflection hack
    RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
    Field jvm = runtime.getClass().getDeclaredField("jvm");

    jvm.setAccessible(true);
    VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);

    Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");

    pid_method.setAccessible(true);

    int pid = (Integer) pid_method.invoke(mgmt);

    return pid;
}
 
Example 17
Source File: JvmRuntimeImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static RuntimeMXBean getRuntimeMXBean() {
    return ManagementFactory.getRuntimeMXBean();
}
 
Example 18
Source File: GetSystemProperties.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void runTest() throws Exception {
    RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();

    // Print all system properties
    Map<String,String> props = mbean.getSystemProperties();
    printProperties(props);

    // Add new system properties
    System.setProperty(KEY1, VALUE1);
    System.setProperty(KEY2, VALUE2);

    Map<String,String> props1 = mbean.getSystemProperties();
    String value1 = props1.get(KEY1);
    if (value1 == null || !value1.equals(VALUE1)) {
        throw new RuntimeException(KEY1 + " property found" +
             " with value = " + value1 +
             " but expected to be " + VALUE1);
    }

    String value2 = props1.get(KEY2);
    if (value2 == null || !value2.equals(VALUE2)) {
        throw new RuntimeException(KEY2 + " property found" +
             " with value = " + value2 +
             " but expected to be " + VALUE2);
    }

    String value3 = props1.get(KEY3);
    if (value3 != null) {
        throw new RuntimeException(KEY3 + " property found" +
             " but should not exist" );
    }

    // Add new system properties but are not Strings
    Properties sp = System.getProperties();
    sp.put(KEY3, VALUE3);
    sp.put(KEY4, VALUE4);

    Map<String,String> props2 = mbean.getSystemProperties();
    // expect the system properties returned should be
    // same as the one before adding KEY3 and KEY4
    if (!props1.equals(props2)) {
        throw new RuntimeException("Two copies of system properties " +
            "are expected to be equal");
    }

    System.out.println("Test passed.");
}
 
Example 19
Source File: GetSystemProperties.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void runTest() throws Exception {
    RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();

    // Print all system properties
    Map<String,String> props = mbean.getSystemProperties();
    printProperties(props);

    // Add new system properties
    System.setProperty(KEY1, VALUE1);
    System.setProperty(KEY2, VALUE2);

    Map<String,String> props1 = mbean.getSystemProperties();
    String value1 = props1.get(KEY1);
    if (value1 == null || !value1.equals(VALUE1)) {
        throw new RuntimeException(KEY1 + " property found" +
             " with value = " + value1 +
             " but expected to be " + VALUE1);
    }

    String value2 = props1.get(KEY2);
    if (value2 == null || !value2.equals(VALUE2)) {
        throw new RuntimeException(KEY2 + " property found" +
             " with value = " + value2 +
             " but expected to be " + VALUE2);
    }

    String value3 = props1.get(KEY3);
    if (value3 != null) {
        throw new RuntimeException(KEY3 + " property found" +
             " but should not exist" );
    }

    // Add new system properties but are not Strings
    Properties sp = System.getProperties();
    sp.put(KEY3, VALUE3);
    sp.put(KEY4, VALUE4);

    Map<String,String> props2 = mbean.getSystemProperties();
    // expect the system properties returned should be
    // same as the one before adding KEY3 and KEY4
    if (!props1.equals(props2)) {
        throw new RuntimeException("Two copies of system properties " +
            "are expected to be equal");
    }

    System.out.println("Test passed.");
}
 
Example 20
Source File: GetSystemProperties.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private static void runTest() throws Exception {
    RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();

    // Print all system properties
    Map<String,String> props = mbean.getSystemProperties();
    printProperties(props);

    // Add new system properties
    System.setProperty(KEY1, VALUE1);
    System.setProperty(KEY2, VALUE2);

    Map<String,String> props1 = mbean.getSystemProperties();
    String value1 = props1.get(KEY1);
    if (value1 == null || !value1.equals(VALUE1)) {
        throw new RuntimeException(KEY1 + " property found" +
             " with value = " + value1 +
             " but expected to be " + VALUE1);
    }

    String value2 = props1.get(KEY2);
    if (value2 == null || !value2.equals(VALUE2)) {
        throw new RuntimeException(KEY2 + " property found" +
             " with value = " + value2 +
             " but expected to be " + VALUE2);
    }

    String value3 = props1.get(KEY3);
    if (value3 != null) {
        throw new RuntimeException(KEY3 + " property found" +
             " but should not exist" );
    }

    // Add new system properties but are not Strings
    Properties sp = System.getProperties();
    sp.put(KEY3, VALUE3);
    sp.put(KEY4, VALUE4);

    Map<String,String> props2 = mbean.getSystemProperties();
    // expect the system properties returned should be
    // same as the one before adding KEY3 and KEY4
    if (!props1.equals(props2)) {
        throw new RuntimeException("Two copies of system properties " +
            "are expected to be equal");
    }

    System.out.println("Test passed.");
}