How do I get the up time of a JVM?

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



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 Saryada

Founder at Kode Java Org
I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.