Example usage for java.lang.management RuntimeMXBean getStartTime

List of usage examples for java.lang.management RuntimeMXBean getStartTime

Introduction

In this page you can find the example usage for java.lang.management RuntimeMXBean getStartTime.

Prototype

public long getStartTime();

Source Link

Document

Returns the start time of the Java virtual machine in milliseconds.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {
    RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
    System.out.println(new Date(mx.getStartTime()));
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
    System.out.println(mx.getBootClassPath());
    System.out.println(mx.getClassPath());

    System.out.println(mx.getInputArguments());
    System.out.println(mx.getSystemProperties());

    System.out.println(new Date(mx.getStartTime()));
    System.out.println(mx.getUptime() + " ms");

}

From source file:net.centro.rtb.monitoringcenter.infos.JvmInfo.java

public static JvmInfo create() {
    JvmInfo jvmInfo = new JvmInfo();

    jvmInfo.specVersion = SystemUtils.JAVA_SPECIFICATION_VERSION;
    jvmInfo.classVersion = SystemUtils.JAVA_CLASS_VERSION;
    jvmInfo.jreVersion = SystemUtils.JAVA_VERSION;
    jvmInfo.jreVendor = SystemUtils.JAVA_VENDOR;
    jvmInfo.vmName = SystemUtils.JAVA_VM_NAME;
    jvmInfo.vmVendor = SystemUtils.JAVA_VM_VENDOR;
    jvmInfo.vmVersion = SystemUtils.JAVA_VM_VERSION;

    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    jvmInfo.inputArguments = new ArrayList<>(runtimeMXBean.getInputArguments());
    jvmInfo.startedTimestamp = new Date(runtimeMXBean.getStartTime());

    jvmInfo.defaultTimeZone = TimeZone.getDefault().getID();
    jvmInfo.defaultCharset = Charset.defaultCharset().displayName();

    return jvmInfo;
}

From source file:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java

private static String getBuild() {
    String build = System.getProperty("org.callimachusproject.test.build");
    String implementationVersion = Version.class.getPackage().getImplementationVersion();
    if (build != null) {
        return build;
    } else if (implementationVersion != null) {
        return implementationVersion;
    } else {/*from w  ww  .  j  a v a  2s. c  om*/
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
        long startTime = bean.getStartTime();
        long code = startTime % (1000 * 60 * 60 * 24 * 30) / 1000 / 60;
        String version = Version.getInstance().getVersionCode();
        return version + "+" + Long.toHexString(code);
    }
}

From source file:com.searchbox.framework.web.SystemController.java

@ModelAttribute("jvmInfo")
public static Map<String, Object> getJvmInfo() {
    Map<String, Object> jvm = new HashMap<String, Object>();

    final String javaVersion = System.getProperty("java.specification.version", "unknown");
    final String javaVendor = System.getProperty("java.specification.vendor", "unknown");
    final String javaName = System.getProperty("java.specification.name", "unknown");
    final String jreVersion = System.getProperty("java.version", "unknown");
    final String jreVendor = System.getProperty("java.vendor", "unknown");
    final String vmVersion = System.getProperty("java.vm.version", "unknown");
    final String vmVendor = System.getProperty("java.vm.vendor", "unknown");
    final String vmName = System.getProperty("java.vm.name", "unknown");

    // Summary Info
    jvm.put("version", jreVersion + " " + vmVersion);
    jvm.put("name", jreVendor + " " + vmName);

    // details//w w w  .jav a  2 s  . c  om
    Map<String, Object> java = new HashMap<String, Object>();
    java.put("vendor", javaVendor);
    java.put("name", javaName);
    java.put("version", javaVersion);
    jvm.put("spec", java);
    Map<String, Object> jre = new HashMap<String, Object>();
    jre.put("vendor", jreVendor);
    jre.put("version", jreVersion);
    jvm.put("jre", jre);
    Map<String, Object> vm = new HashMap<String, Object>();
    vm.put("vendor", vmVendor);
    vm.put("name", vmName);
    vm.put("version", vmVersion);
    jvm.put("vm", vm);

    Runtime runtime = Runtime.getRuntime();
    jvm.put("processors", runtime.availableProcessors());

    // not thread safe, but could be thread local
    DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ROOT));

    Map<String, Object> mem = new HashMap<String, Object>();
    Map<String, Object> raw = new HashMap<String, Object>();
    long free = runtime.freeMemory();
    long max = runtime.maxMemory();
    long total = runtime.totalMemory();
    long used = total - free;
    double percentUsed = ((double) (used) / (double) max) * 100;
    raw.put("free", free);
    mem.put("free", humanReadableUnits(free, df));
    raw.put("total", total);
    mem.put("total", humanReadableUnits(total, df));
    raw.put("max", max);
    mem.put("max", humanReadableUnits(max, df));
    raw.put("used", used);
    mem.put("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")");
    raw.put("used%", percentUsed);

    mem.put("raw", raw);
    jvm.put("memory", mem);

    // JMX properties -- probably should be moved to a different handler
    Map<String, Object> jmx = new HashMap<String, Object>();
    try {
        RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
        jmx.put("bootclasspath", mx.getBootClassPath());
        jmx.put("classpath", mx.getClassPath());

        // the input arguments passed to the Java virtual machine
        // which does not include the arguments to the main method.
        jmx.put("commandLineArgs", mx.getInputArguments());

        jmx.put("startTime", new Date(mx.getStartTime()));
        jmx.put("upTimeMS", mx.getUptime());

    } catch (Exception e) {
        LOGGER.warn("Error getting JMX properties", e);
    }
    jvm.put("jmx", jmx);
    return jvm;
}

From source file:com.netflix.explorers.AppConfigGlobalModelContext.java

@Override
public long getStartTime() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    return rb.getStartTime();
}

From source file:net.risesoft.soa.asf.web.controller.SystemController.java

private List<SysInfo> getVMInfo() {
    List list = new ArrayList();
    String group = "3. VM ?";
    RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean();
    list.add(new SysInfo("BootClassPath", rt.getBootClassPath(), group));
    list.add(new SysInfo("ClassPath", rt.getClassPath(), group));
    list.add(new SysInfo("LibraryPath", rt.getLibraryPath(), group));
    list.add(new SysInfo("ManagementSpecVersion", rt.getManagementSpecVersion(), group));
    list.add(new SysInfo("Name", rt.getName(), group));
    list.add(new SysInfo("SpecName", rt.getSpecName(), group));
    list.add(new SysInfo("SpecVendor", rt.getSpecVendor(), group));
    list.add(new SysInfo("SpecVersion", rt.getSpecVersion(), group));
    list.add(new SysInfo("VmName", rt.getVmName(), group));
    list.add(new SysInfo("VmVendor", rt.getVmVendor(), group));
    list.add(new SysInfo("VmVersion", rt.getVmVersion(), group));
    list.add(new SysInfo("StartTime", DateFormat.getDateTimeInstance().format(new Date(rt.getStartTime())),
            group));//from w w w  .  java 2s  .co m

    list.add(new SysInfo("UpTime", this.helper.getUpTimeStr(rt.getUptime()), group));
    list.add(new SysInfo("InputArguments", rt.getInputArguments(), group));

    group = "6. ?";
    Map<String, String> sysProps = rt.getSystemProperties();
    for (Map.Entry entry : sysProps.entrySet()) {
        list.add(new SysInfo((String) entry.getKey(), entry.getValue(), group));
    }
    Collections.sort(list, new Comparator() {
        public int compare(SystemController.SysInfo o1, SystemController.SysInfo o2) {
            String key1 = o1.getKey();
            String key2 = o2.getKey();
            return key1.compareToIgnoreCase(key2);
        }
    });
    return list;
}

From source file:com.eurelis.opencms.admin.systeminformation.CmsSystemInformationOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *//*  www  . j a  v a2s .c  o m*/
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    //JVM uptime
    Date date = new Date(runtimeBean.getUptime());
    java.text.SimpleDateFormat simpleFormatH = new java.text.SimpleDateFormat("HH");
    java.text.SimpleDateFormat simpleFormatM = new java.text.SimpleDateFormat("mm");
    java.text.SimpleDateFormat simpleFormatS = new java.text.SimpleDateFormat("ss");
    String jvmuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    //JVM start time
    date = new Date(runtimeBean.getStartTime());
    String jvmstarttimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    //OpenCms runtime
    date = new Date(OpenCms.getSystemInfo().getRuntime());
    String opencmsruntimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    //OpenCms startup time
    date = new Date(OpenCms.getSystemInfo().getStartupTime());
    String opencmsstartuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    setOperatingSystem("" + osBean.getName());
    setJavaVersion(System.getProperty("java.version"));
    setJvmUptime("" + jvmuptimestring);
    setJvmStarttime("" + jvmstarttimestring);
    setOpenCmsVersion(OpenCms.getSystemInfo().getVersionNumber());
    setOpenCmsRuntime("" + opencmsruntimestring);
    setOpenCmsStartupTime("" + opencmsstartuptimestring);

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

}

From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java

@GET
@RequireAdmin/* w  w  w .ja  v a 2  s .c om*/
@APIDescription("Gets the application system status")
@Produces({ MediaType.APPLICATION_JSON })
@DataType(ApplicationStatus.class)
@Path("/status")
public Response getApplicationStatus() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

    ApplicationStatus applicationStatus = new ApplicationStatus();
    applicationStatus.setApplicationVersion(PropertiesManager.getApplicationVersion());
    applicationStatus.setProcessorCount(operatingSystemMXBean.getAvailableProcessors());
    applicationStatus.setSystemLoad(operatingSystemMXBean.getSystemLoadAverage());
    applicationStatus.setSystemProperties(runtimeMXBean.getSystemProperties());

    applicationStatus.getHeapMemoryStatus().setName("Heap");
    applicationStatus.getHeapMemoryStatus().setDetails(memoryMXBean.getHeapMemoryUsage().toString());
    applicationStatus.getHeapMemoryStatus()
            .setInitKb(memoryMXBean.getHeapMemoryUsage().getInit() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getInit() / 1024
                    : 0);
    applicationStatus.getHeapMemoryStatus()
            .setUsedKb(memoryMXBean.getHeapMemoryUsage().getUsed() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getUsed() / 1024
                    : 0);
    applicationStatus.getHeapMemoryStatus()
            .setMaxKb(memoryMXBean.getHeapMemoryUsage().getMax() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getMax() / 1024
                    : 0);
    applicationStatus.getHeapMemoryStatus()
            .setCommitedKb(memoryMXBean.getHeapMemoryUsage().getCommitted() != 0
                    ? memoryMXBean.getHeapMemoryUsage().getCommitted() / 1024
                    : 0);

    applicationStatus.getNonHeapMemoryStatus().setName("Non-Heap");
    applicationStatus.getNonHeapMemoryStatus().setDetails(memoryMXBean.getNonHeapMemoryUsage().toString());
    applicationStatus.getNonHeapMemoryStatus()
            .setInitKb(memoryMXBean.getNonHeapMemoryUsage().getInit() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getInit() / 1024
                    : 0);
    applicationStatus.getNonHeapMemoryStatus()
            .setUsedKb(memoryMXBean.getNonHeapMemoryUsage().getUsed() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getUsed() / 1024
                    : 0);
    applicationStatus.getNonHeapMemoryStatus()
            .setMaxKb(memoryMXBean.getNonHeapMemoryUsage().getMax() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getMax() / 1024
                    : 0);
    applicationStatus.getNonHeapMemoryStatus()
            .setCommitedKb(memoryMXBean.getNonHeapMemoryUsage().getCommitted() != 0
                    ? memoryMXBean.getNonHeapMemoryUsage().getCommitted() / 1024
                    : 0);

    applicationStatus.setLiveThreadCount(threadMXBean.getThreadCount());
    applicationStatus.setTotalThreadCount(threadMXBean.getTotalStartedThreadCount());

    applicationStatus.setStartTime(new Date(runtimeMXBean.getStartTime()));
    applicationStatus.setUpTime(TimeUtil.millisToString(runtimeMXBean.getUptime()));

    for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) {
        applicationStatus.getGarbageCollectionInfos()
                .add(TimeUtil.millisToString(garbageCollectorMXBean.getCollectionTime()) + " - ("
                        + garbageCollectorMXBean.getCollectionCount() + ")");
    }

    for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
        MemoryPoolStatus memoryPoolStatus = new MemoryPoolStatus();
        memoryPoolStatus.setName(memoryPoolMXBean.getName() + " - " + memoryPoolMXBean.getType());
        memoryPoolStatus.setDetails(memoryPoolMXBean.getUsage().toString());
        memoryPoolStatus.setInitKb(
                memoryPoolMXBean.getUsage().getInit() != 0 ? memoryPoolMXBean.getUsage().getInit() / 1024 : 0);
        memoryPoolStatus.setUsedKb(
                memoryPoolMXBean.getUsage().getUsed() != 0 ? memoryPoolMXBean.getUsage().getUsed() / 1024 : 0);
        memoryPoolStatus.setMaxKb(
                memoryPoolMXBean.getUsage().getMax() != 0 ? memoryPoolMXBean.getUsage().getMax() / 1024 : 0);
        memoryPoolStatus.setCommitedKb(memoryPoolMXBean.getUsage().getCommitted() != 0
                ? memoryPoolMXBean.getUsage().getCommitted() / 1024
                : 0);

        applicationStatus.getMemoryPools().add(memoryPoolStatus);
    }

    return sendSingleEntityResponse(applicationStatus);
}

From source file:org.apache.solr.handler.admin.SystemInfoHandler.java

/**
 * Get JVM Info - including memory info/*from w ww.j a v a  2  s . c  o m*/
 */
public static SimpleOrderedMap<Object> getJvmInfo() {
    SimpleOrderedMap<Object> jvm = new SimpleOrderedMap<Object>();
    jvm.add("version", System.getProperty("java.vm.version"));
    jvm.add("name", System.getProperty("java.vm.name"));

    Runtime runtime = Runtime.getRuntime();
    jvm.add("processors", runtime.availableProcessors());

    long used = runtime.totalMemory() - runtime.freeMemory();
    // not thread safe, but could be thread local
    DecimalFormat df = new DecimalFormat("#.#");
    double percentUsed = ((double) (used) / (double) runtime.maxMemory()) * 100;

    SimpleOrderedMap<Object> mem = new SimpleOrderedMap<Object>();
    mem.add("free", humanReadableUnits(runtime.freeMemory(), df));
    mem.add("total", humanReadableUnits(runtime.totalMemory(), df));
    mem.add("max", humanReadableUnits(runtime.maxMemory(), df));
    mem.add("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")");
    jvm.add("memory", mem);

    // JMX properties -- probably should be moved to a different handler
    SimpleOrderedMap<Object> jmx = new SimpleOrderedMap<Object>();
    try {
        RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
        jmx.add("bootclasspath", mx.getBootClassPath());
        jmx.add("classpath", mx.getClassPath());

        // the input arguments passed to the Java virtual machine
        // which does not include the arguments to the main method.
        jmx.add("commandLineArgs", mx.getInputArguments());
        // a map of names and values of all system properties.
        //jmx.add( "SYSTEM PROPERTIES", mx.getSystemProperties());

        jmx.add("startTime", new Date(mx.getStartTime()));
        jmx.add("upTimeMS", mx.getUptime());
    } catch (Exception e) {
        log.warn("Error getting JMX properties", e);
    }
    jvm.add("jmx", jmx);
    return jvm;
}