SupportWriter space ↗
← Back to the journal
Core API

How do I get the uptime of a JVM?

The following code snippet demonstrates how to get the time for how long has the JVM been running. package org.kodejava.lang.management; import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; public class GetUptime { public static void main(String[] args) { RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); // Returns the uptime of the Java virtual machine in // milliseconds. long uptime = bean.getUptime(); System.out.printf("Uptime...

DWayan · 12 May 2010 · 1 min read

Article by Wayan · Source: Kode Java ↗

The following code snippet demonstrates how to get the time for how long has the JVM been running.

package org.kodejava.lang.management;

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

public class GetUptime {
    public static void main(String[] args) {
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();

        // Returns the uptime of the Java virtual machine in
        // milliseconds.
        long uptime = bean.getUptime();
        System.out.printf("Uptime = %d (ms).", uptime);
    }
}

The output of the code snippet above:

Uptime = 125 (ms).
← Explore more notes