Java虚拟机的运行时系统管理界面中的RuntimeMXBean-
RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();
让我们使用getUptime()
方法获得JVM正常运行时间-
runtimeMX.getUptime()
以下是一个例子-
import java.lang.management.ManagementFactory; import java.lang.management.RuntimeMXBean; import java.util.Date; public class Demo { public static void main(String args[]) throws Exception { RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean(); System.out.println("JVM Uptime = "+runtimeMX.getUptime() + " ms"); } }
输出结果
JVM Uptime = 81 ms
让我们再次运行代码,以获取以下输出-
JVM Uptime = 78 ms