![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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