aleroot aleroot - 2 years ago 185
Java Question

Get application uptime

I've written an application in java and I want to add a feature to report the uptime of the application. Is there a Class/method in the JVM that can do this?

Should I save the timestamp when application starts, then calculate the difference with the current uptime in the moment of the request?

What's a better way to retrieve application uptime in Java?

Answer Source

You can use RuntimeMXBean.getUptime()

RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
long uptime = rb.getUptime();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download