Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Get the JVM uptime from RuntimeMXBean in Java
RuntimeMXBean in the management interface for the runtime system of the Java virtual machine −
RuntimeMXBean runtimeMX = ManagementFactory.getRuntimeMXBean();
Let us get the JVM uptime using the getUptime() method −
runtimeMX.getUptime()
The following is an example −
Example
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");
}
}
Output
JVM Uptime = 81 ms
Let us run the code again, to get the following output −
JVM Uptime = 78 ms
Advertisements
