The following code snippet demonstrates how to get the time for how long has the JVM been running.
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)
Latest posts by Wayan (see all)
- How do I create a generic class in Java? - January 1, 2021
- How do I convert java.util.TimeZone to java.time.ZoneId? - April 25, 2020
- How do I get a list of all TimeZones Ids using Java 8? - April 25, 2020