How do I get the up time of a JVM?

package org.kodejava.example.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 up time of the Java virtual machine in
        // milliseconds.
        long upTime = bean.getUptime();
        System.out.printf("Up Time = %d (ms)", upTime);
    }
}

The output of the code snippet above:

Up Time = 246 (ms)

Wayan

Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. Support me by donating.

Leave a Reply