Get the system properties or the JVM uptimeTag(s): Environment


The RuntimeMXBean defines several convenient methods for accessing system properties about the Java virtual machine.

[J2SE 1.5]

import java.util.Date;

import java.lang.management.RuntimeMXBean;
import java.lang.management.ManagementFactory;

class JMXTest {
  public static void main(String args[]) {
    JMXTest x = new JMXTest();
    x.doit();
  }

  public void doit() {
    try{
      RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
      System.out.println("BOOTCLASSPATH:\n" + mx.getBootClassPath());
      System.out.println("CLASSPATH:\n" + mx.getClassPath());

      // the input arguments passed to the Java virtual machine
      // which does not include the arguments to the main method.
      System.out.println("COMMAND LINE ARGS:\n" + mx.getInputArguments());
      // a map of names and values of all system properties.
      System.out.println("SYSTEM PROPERTIES:\n" + mx.getSystemProperties());

      System.out.println("VM start time : " +  new Date(mx.getStartTime()));
      System.out.println("VM up time : " +  mx.getUptime() + " ms");

    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

blog comments powered by Disqus